Skip to content

Commit 1bbd447

Browse files
authored
Merge pull request #2670 from jreklund/nginx-documentation
Added default configuration for Nginx in "Running Your App" [ci-skip]
2 parents c90194f + 6e89a67 commit 1bbd447

2 files changed

Lines changed: 62 additions & 23 deletions

File tree

user_guide_src/source/general/urls.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ the above Apache configuration:
6262
.. code-block:: nginx
6363
6464
location / {
65-
try_files $uri $uri/ /index.php/$args;
65+
try_files $uri $uri/ /index.php$is_args$args;
6666
}
6767
6868
This will first look for a file or directory matching the URI (constructing the full path to each file from the

user_guide_src/source/installation/running.rst

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Running Your App
55
:local:
66
:depth: 1
77

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.
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.
1010
This section addresses how to use each technique, and explains some of the pros and cons of them.
1111

1212
If you’re new to CodeIgniter, please read the :doc:`Getting Started </intro/index>`
@@ -72,24 +72,24 @@ The local development server can be customized with three command line options:
7272
Hosting with Apache
7373
=================================================
7474

75-
A CodeIgniter4 webapp is normally hosted on a web server.
75+
A CodeIgniter4 webapp is normally hosted on a web server.
7676
Apache’s ``httpd`` is the "standard" platform, and assumed in much of our documentation.
7777

78-
Apache is bundled with many platforms, but can also be downloaded in a bundle
79-
with a database engine and PHP from [Bitnami](https://bitnami.com/stacks/infrastructure).
78+
Apache is bundled with many platforms, but can also be downloaded in a bundle
79+
with a database engine and PHP from `Bitnami <https://bitnami.com/stacks/infrastructure>`_.
8080

8181
.htaccess
8282
-------------------------------------------------------
8383

84-
The “mod_rewrite” module enables URLs without “index.php” in them, and is assumed
84+
The “mod_rewrite” module enables URLs without “index.php” in them, and is assumed
8585
in our user guide.
8686

87-
Make sure that the rewrite module is enabled (uncommented) in the main
87+
Make sure that the rewrite module is enabled (uncommented) in the main
8888
configuration file, eg. ``apache2/conf/httpd.conf``::
8989

9090
LoadModule rewrite_module modules/mod_rewrite.so
9191

92-
Also make sure that the default document root's <Directory> element enables this too,
92+
Also make sure that the default document root's <Directory> element enables this too,
9393
in the "AllowOverride" setting::
9494

9595
<Directory "/opt/lamp7.2/apache2/htdocs">
@@ -101,21 +101,21 @@ in the "AllowOverride" setting::
101101
Virtual Hosting
102102
-------------------------------------------------------
103103

104-
We recommend using “virtual hosting” to run your apps.
104+
We recommend using “virtual hosting” to run your apps.
105105
You can set up different aliases for each of the apps you work on,
106106

107-
Make sure that the virtual hosting module is enabled (uncommented) in the main
107+
Make sure that the virtual hosting module is enabled (uncommented) in the main
108108
configuration file, eg. ``apache2/conf/httpd.conf``::
109109

110110
LoadModule vhost_alias_module modules/mod_vhost_alias.so
111111

112-
Add a host alias in your “hosts” file, typically ``/etc/hosts`` on unix-type platforms,
113-
or ``c:/Windows/System32/drivers/etc/hosts`` on Windows.
112+
Add a host alias in your “hosts” file, typically ``/etc/hosts`` on unix-type platforms,
113+
or ``c:/Windows/System32/drivers/etc/hosts`` on Windows.
114114
Add a line to the file. This could be "myproject.local" or "myproject.test", for instance::
115115

116116
127.0.0.1 myproject.local
117117

118-
Add a <VirtualHost> element for your webapp inside the virtual hosting configuration,
118+
Add a <VirtualHost> element for your webapp inside the virtual hosting configuration,
119119
eg. ``apache2/conf/extra/httpd-vhost.conf``::
120120

121121
<VirtualHost *:80>
@@ -125,7 +125,7 @@ eg. ``apache2/conf/extra/httpd-vhost.conf``::
125125
CustomLog "logs/myproject-access_log" common
126126
</VirtualHost>
127127

128-
If your project folder is not a subfolder of the Apache document root, then your
128+
If your project folder is not a subfolder of the Apache document root, then your
129129
<VirtualHost> element may need a nested <Directory> element to grant the web s
130130
erver access to the files.
131131

@@ -136,12 +136,51 @@ With the above configuration, your webapp would be accessed with the URL ``http:
136136

137137
Apache needs to be restarted whenever you change its configuration.
138138

139+
Hosting with Nginx
140+
=================================================
141+
Nginx is the second most widely used HTTP server for web hosting.
142+
Here you can find an example configuration using PHP 7.3 FPM (unix sockets) under Ubuntu Server.
143+
144+
This configuration enables URLs without “index.php” in them and using CodeIgniter's “404 - File Not Found” for URLs ending with “.php”.
145+
146+
.. code-block:: nginx
147+
148+
server {
149+
listen 80;
150+
listen [::]:80;
151+
152+
server_name example.com;
153+
154+
root /var/www/example.com/public;
155+
index index.php index.html index.htm;
156+
157+
location / {
158+
try_files $uri $uri/ /index.php$is_args$args;
159+
}
160+
161+
location ~ \.php$ {
162+
include snippets/fastcgi-php.conf;
163+
164+
# With php-fpm:
165+
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
166+
# With php-cgi:
167+
# fastcgi_pass 127.0.0.1:9000;
168+
}
169+
170+
error_page 404 /index.php;
171+
172+
# deny access to hidden files such as .htaccess
173+
location ~ /\. {
174+
deny all;
175+
}
176+
}
177+
139178
Hosting with Vagrant
140179
=================================================
141180

142-
Virtualization is an effective way to test your webapp in the environment you
143-
plan to deploy on, even if you develop on a different one.
144-
Even if you are using the same platform for both, virtualization provides an
181+
Virtualization is an effective way to test your webapp in the environment you
182+
plan to deploy on, even if you develop on a different one.
183+
Even if you are using the same platform for both, virtualization provides an
145184
isolated environment for testing.
146185

147186
The codebase comes with a ``VagrantFile.dist``, that can be copied to ``VagrantFile``
@@ -150,11 +189,11 @@ and tailored for your system, for instance enabling access to specific database
150189
Setting Up
151190
-------------------------------------------------------
152191

153-
It assumes that you have installed `VirtualBox <https://www.virtualbox.org/wiki/Downloads>`_ and
154-
`Vagrant <https://www.vagrantup.com/downloads.html>`_
192+
It assumes that you have installed `VirtualBox <https://www.virtualbox.org/wiki/Downloads>`_ and
193+
`Vagrant <https://www.vagrantup.com/downloads.html>`_
155194
for your platform.
156195

157-
The Vagrant configuration file assumes you have set up a `ubuntu/bionic64 Vagrant box
196+
The Vagrant configuration file assumes you have set up a `ubuntu/bionic64 Vagrant box
158197
<https://app.vagrantup.com/ubuntu/boxes/bionic64>`_ on your system::
159198

160199
vagrant box add ubuntu/bionic64
@@ -166,6 +205,6 @@ Once set up, you can then launch your webapp inside a VM, with the command::
166205

167206
vagrant up
168207

169-
Your webapp will be accessible at ``http://localhost:8080``, with the code coverage
170-
report for your build at ``http://localhost:8081`` and the user guide for
208+
Your webapp will be accessible at ``http://localhost:8080``, with the code coverage
209+
report for your build at ``http://localhost:8081`` and the user guide for
171210
it at ``http://localhost:8082``.

0 commit comments

Comments
 (0)