You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If your project folder is not a subfolder of the Apache document root, then your
148
-
``<VirtualHost>`` element may need a nested ``<Directory>`` element to grant the web server access to the files.
176
+
The above configuration assumes the project folder is located as follows:
177
+
178
+
.. code-block:: text
149
179
150
-
With mod_userdir (Shared Hosts)
151
-
--------------------------------
180
+
apache2/
181
+
├── myproject/ (Project Folder)
182
+
│ └── public/ (DocumentRoot for myproject.local)
183
+
└── htdocs/
184
+
185
+
Testing
186
+
-------
187
+
188
+
With the above configuration, your webapp would be accessed with the URL **http://myproject.local/** in your browser.
189
+
190
+
Apache needs to be restarted whenever you change its configuration.
191
+
192
+
Hosting with mod_userdir (Shared Hosts)
193
+
=======================================
152
194
153
195
A common practice in shared hosting environments is to use the Apache module "mod_userdir" to enable per-user Virtual Hosts automatically. Additional configuration is required to allow CodeIgniter4 to be run from these per-user directories.
154
196
155
197
The following assumes that the server is already configured for mod_userdir. A guide to enabling this module is available `in the Apache documentation <https://httpd.apache.org/docs/2.4/howto/public_html.html>`_.
156
198
157
199
Because CodeIgniter4 expects the server to find the framework front controller at **public/index.php** by default, you must specify this location as an alternative to search for the request (even if CodeIgniter4 is installed within the per-user web directory).
158
200
159
-
The default user web directory **~/public_html** is specified by the ``UserDir`` directive, typically in **apache2/mods-available/userdir.conf** or **apache2/conf/extra/httpd-userdir.conf**::
201
+
The default user web directory **~/public_html** is specified by the ``UserDir`` directive, typically in **apache2/mods-available/userdir.conf** or **apache2/conf/extra/httpd-userdir.conf**:
202
+
203
+
.. code-block:: apache
160
204
161
205
UserDir public_html
162
206
163
-
So you will need to configure Apache to look for CodeIgniter's public directory first before trying to serve the default::
207
+
So you will need to configure Apache to look for CodeIgniter's public directory first before trying to serve the default:
208
+
209
+
.. code-block:: apache
164
210
165
211
UserDir "public_html/public" "public_html"
166
212
167
-
Be sure to specify options and permissions for the CodeIgniter public directory as well. A **userdir.conf** might look like::
213
+
Be sure to specify options and permissions for the CodeIgniter public directory as well. A **userdir.conf** might look like:
214
+
215
+
.. code-block:: apache
168
216
169
217
<IfModule mod_userdir.c>
170
218
UserDir "public_html/public" "public_html"
171
219
UserDir disabled root
172
220
173
221
<Directory /home/*/public_html>
174
-
AllowOverride All
175
-
Options MultiViews Indexes FollowSymLinks
176
-
<Limit GET POST OPTIONS>
177
-
# Apache <= 2.2:
178
-
# Order allow,deny
179
-
# Allow from all
180
-
181
-
# Apache >= 2.4:
182
-
Require all granted
183
-
</Limit>
184
-
<LimitExcept GET POST OPTIONS>
185
-
# Apache <= 2.2:
186
-
# Order deny,allow
187
-
# Deny from all
188
-
189
-
# Apache >= 2.4:
190
-
Require all denied
191
-
</LimitExcept>
222
+
AllowOverride All
223
+
Options MultiViews Indexes FollowSymLinks
224
+
<Limit GET POST OPTIONS>
225
+
# Apache <= 2.2:
226
+
# Order allow,deny
227
+
# Allow from all
228
+
229
+
# Apache >= 2.4:
230
+
Require all granted
231
+
</Limit>
232
+
<LimitExcept GET POST OPTIONS>
233
+
# Apache <= 2.2:
234
+
# Order deny,allow
235
+
# Deny from all
236
+
237
+
# Apache >= 2.4:
238
+
Require all denied
239
+
</LimitExcept>
192
240
</Directory>
193
241
194
242
<Directory /home/*/public_html/public>
195
-
AllowOverride All
196
-
Options MultiViews Indexes FollowSymLinks
197
-
<Limit GET POST OPTIONS>
198
-
# Apache <= 2.2:
199
-
# Order allow,deny
200
-
# Allow from all
201
-
202
-
# Apache >= 2.4:
203
-
Require all granted
204
-
</Limit>
205
-
<LimitExcept GET POST OPTIONS>
206
-
# Apache <= 2.2:
207
-
# Order deny,allow
208
-
# Deny from all
209
-
210
-
# Apache >= 2.4:
211
-
Require all denied
212
-
</LimitExcept>
243
+
AllowOverride All
244
+
Options MultiViews Indexes FollowSymLinks
245
+
<Limit GET POST OPTIONS>
246
+
# Apache <= 2.2:
247
+
# Order allow,deny
248
+
# Allow from all
249
+
250
+
# Apache >= 2.4:
251
+
Require all granted
252
+
</Limit>
253
+
<LimitExcept GET POST OPTIONS>
254
+
# Apache <= 2.2:
255
+
# Order deny,allow
256
+
# Deny from all
257
+
258
+
# Apache >= 2.4:
259
+
Require all denied
260
+
</LimitExcept>
213
261
</Directory>
214
262
</IfModule>
215
263
216
-
Setting Environment
217
-
-------------------
218
-
219
-
See :ref:`Handling Multiple Environments <environment-apache>`.
264
+
Removing the index.php
265
+
======================
220
266
221
-
Testing
222
-
-------
267
+
See :ref:`CodeIgniter URLs <urls-remove-index-php-apache>`.
223
268
224
-
With the above configuration, your webapp would be accessed with the URL **http://myproject.local/** in your browser.
269
+
Setting Environment
270
+
===================
225
271
226
-
Apache needs to be restarted whenever you change its configuration.
272
+
See :ref:`Handling Multiple Environments <environment-apache>`.
227
273
274
+
******************
228
275
Hosting with Nginx
229
-
==================
276
+
******************
230
277
231
278
Nginx is the second most widely used HTTP server for web hosting.
232
279
Here you can find an example configuration using PHP 8.1 FPM (unix sockets) under Ubuntu Server.
233
280
234
281
default.conf
235
-
------------
282
+
============
236
283
237
284
This configuration enables URLs without "index.php" in them and using CodeIgniter's "404 - File Not Found" for URLs ending with ".php".
238
285
@@ -269,12 +316,13 @@ This configuration enables URLs without "index.php" in them and using CodeIgnite
269
316
}
270
317
271
318
Setting Environment
272
-
-------------------
319
+
===================
273
320
274
321
See :ref:`Handling Multiple Environments <environment-nginx>`.
275
322
323
+
*********************
276
324
Bootstrapping the App
277
-
=====================
325
+
*********************
278
326
279
327
In some scenarios you will want to load the framework without actually running the whole
280
328
application. This is particularly useful for unit testing your project, but may also be
0 commit comments