11Running Your App
22###############################################################################
33
4- A CodeIgniter 4 app can be run in a number of different ways: hosted on a web server,
5- using virtualization, or using CodeIgniter's command line tool for testing.
6- This section addresses how to use
7- each technique, and explains some of the pros and cons of them.
4+ .. contents ::
5+ :local:
6+ :depth: 1
7+
8+ A CodeIgniter 4 app can be run in a number of different ways: hosted on a web server,
9+ using virtualization, or using CodeIgniter’s command line tool for testing.
10+ This section addresses how to use each technique, and explains some of the pros and cons of them.
11+
12+ If you’re new to CodeIgniter, please read the :doc: `Getting Started </intro/index >`
13+ section of the User Guide to begin learning how to build dynamic PHP applications. Enjoy!
814
915Initial Configuration & Setup
1016=================================================
@@ -25,39 +31,14 @@ By default, the application will run using the "production" environment. To
2531take advantage of the debugging tools provided, you should set the environment
2632to "develop".
2733
28- Hosting with Apache
29- =================================================
30-
31- Directions coming soon.
32-
33- Hosting with NGINX
34- =================================================
35-
36- Directions coming soon.
37-
38- Hosting with Vagrant
39- =================================================
40-
41- Directions coming soon.
42-
43- Hosting with Docker
44- =================================================
45-
46- Directions coming soon.
47-
48- Hosting on the Cloud
49- =================================================
50-
51- Directions coming soon.
52-
5334Local Development Server
5435=================================================
5536
5637CodeIgniter 4 comes with a local development server, leveraging PHP's built-in web server
5738with CodeIgniter routing. You can use the ``serve `` script to launch it,
5839with the following command line in the main directory::
5940
60- > php spark serve
41+ php spark serve
6142
6243This will launch the server and you can now view your application in your browser at http://localhost:8080.
6344
@@ -66,26 +47,137 @@ This will launch the server and you can now view your application in your browse
6647
6748If you need to run the site on a host other than simply localhost, you'll first need to add the host
6849to your ``hosts `` file. The exact location of the file varies in each of the main operating systems, though
69- all * nix -type systems (include OS X) will typically keep the file at * */etc/hosts**.
50+ all unix -type systems (include OS X) will typically keep the file at **/etc/hosts **.
7051
7152The local development server can be customized with three command line options:
7253
7354- You can use the ``--host `` CLI option to specify a different host to run the application at::
7455
75- > php spark serve --host=example.dev
56+ php spark serve --host=example.dev
7657
7758- By default, the server runs on port 8080 but you might have more than one site running, or already have
7859 another application using that port. You can use the ``--port `` CLI option to specify a different one::
7960
80- > php spark serve --port=8081
61+ php spark serve --port=8081
8162
8263- You can also specify a specific version of PHP to use, with the ``--php `` CLI option, with its value
8364 set to the path of the PHP executable you want to use::
8465
85- > php spark serve --php=/usr/bin/php7.6.5.4
66+ php spark serve --php=/usr/bin/php7.6.5.4
67+
68+ Hosting with Apache
69+ =================================================
70+
71+ A CodeIgniter4 webapp is normally hosted on a web server.
72+ Apache’s ``httpd `` is the "standard" platform, and assumed in much of our documentation.
73+
74+ Apache is bundled with many platforms, but can also be downloaded in a bundle
75+ with a database engine and PHP from [Bitnami](https://bitnami.com/stacks/infrastructure).
76+
77+ .htaccess
78+ -------------------------------------------------------
79+
80+ The “mod_rewrite” module enables URLs without “index.php” in them, and is assumed
81+ in our user guide.
82+
83+ Make sure that the rewrite module is enabled (uncommented) in the main
84+ configuration file, eg. ``apache2/conf/httpd.conf ``::
85+
86+ LoadModule rewrite_module modules/mod_rewrite.so
87+
88+ Also make sure that the default document root's <Directory> element enables this too,
89+ in the "AllowOverride" setting::
90+
91+ <Directory "/opt/lamp7.2/apache2/htdocs">
92+ Options Indexes FollowSymLinks
93+ AllowOverride All
94+ Require all granted
95+ </Directory>
96+
97+ Virtual Hosting
98+ -------------------------------------------------------
8699
100+ We recommend using “virtual hosting” to run your apps.
101+ You can setup different aliases for each of the apps you work on,
102+
103+ Make sure that the virtual hosting module is enabled (uncommented) in the main
104+ configuration file, eg. ``apache2/conf/httpd.conf ``::
105+
106+ LoadModule vhost_alias_module modules/mod_vhost_alias.so
107+
108+ Add a host alias in your “hosts” file, typically ``/etc/hosts `` on unix-type platforms,
109+ or ``c:/Windows/System32/drivers/etc/hosts `` on Windows.
110+ Add a line to the file. This could be "myproject.local" or "myproject.test", for instance::
111+
112+ 127.0.0.1 myproject.local
113+
114+ Add a <VirtualHost> element for your webapp inside the virtual hosting configuration,
115+ eg. ``apache2/conf/extra/httpd-vhost.conf ``::
116+
117+ <VirtualHost *:80>
118+ DocumentRoot "/opt/lamp7.2/apache2/htdocs/myproject/public"
119+ ServerName myproject.local
120+ ErrorLog "logs/myproject-error_log"
121+ CustomLog "logs/myproject-access_log" common
122+ </VirtualHost>
123+
124+ If your project folder is not a subfolder of the Apache document root, then your
125+ <VirtualHost> element may need a nested <Directory> element to grant the web s
126+ erver access to the files.
127+
128+ Testing
129+ -------------------------------------------------------
130+
131+ With the above configuration, your webapp would be accessed with the URL ``http://myproject.local `` in your browser.
132+
133+ Apache needs to be restarted whenever you change its configuration.
134+
135+ Hosting with NGINX
136+ =================================================
137+
138+ Directions coming soon?
139+
140+ Hosting with Vagrant
141+ =================================================
142+
143+ Virtualization is an effective way to test your webapp in the environment you
144+ plan to deploy on, even if you develop on a different one.
145+ Even if you are using the same platform for both, virtualization provides an
146+ isolated environment for testing.
147+
148+ The codebase comes with a ``VagrantFile.dist ``, that can be copied to ``VagrantFile ``
149+ and tailored for your system, for instance enabling access to specific database or caching engines.
150+
151+ Setup
152+ -------------------------------------------------------
153+
154+ It assumes that you have installed `VirtualBox <https://www.virtualbox.org/wiki/Downloads >`_ and
155+ `Vagrant <https://www.vagrantup.com/downloads.html >`_
156+ for your platform.
157+
158+ The Vagrant configuration file assumes you have the `ubuntu/bionic64 Vagrant box
159+ <https://app.vagrantup.com/ubuntu/boxes/bionic64> `_ setup on your system::
160+
161+ vagrant box add ubuntu/bionic64
162+
163+ Testing
164+ -------------------------------------------------------
165+
166+ Once setup, you can then launch your webapp inside a VM, with the command::
167+
168+ vagrant up
169+
170+ Your webapp will be accessible at ``http://localhost:8080 ``, with the code coverage
171+ report for your build at ``http://localhost:8081 `` and the user guide for
172+ it at ``http://localhost:8082 ``.
173+
174+ Hosting with Docker
175+ =================================================
176+
177+ Directions coming soon?
178+
179+ Hosting on the Cloud
180+ =================================================
87181
182+ Directions coming soon?
88183
89- If you're new to CodeIgniter, please read the :doc: `Getting
90- Started <../intro/index>` section of the User Guide
91- to begin learning how to build dynamic PHP applications. Enjoy!
0 commit comments