@@ -6,13 +6,13 @@ Deployment
66 :local:
77 :depth: 3
88
9- Before deploying your CodeIgniter application to production, there are several
10- things you can do to make your application run more efficiently.
11-
129************
1310Optimization
1411************
1512
13+ Before deploying your CodeIgniter application to production, there are several
14+ things you can do to make your application run more efficiently.
15+
1616This section describes the optimization features that CodeIgniter provides.
1717
1818Composer Optimization
@@ -63,3 +63,80 @@ If you want to use `Preloading <https://www.php.net/manual/en/opcache.preloading
6363we provide a
6464`preload script <https://github.com/codeigniter4/CodeIgniter4/blob/develop/preload.php >`_.
6565
66+ .. _deployment-to-shared-hosting-services :
67+
68+ *************************************
69+ Deployment to Shared Hosting Services
70+ *************************************
71+
72+ .. important ::
73+ **index.php ** is no longer in the root of the project! It has been moved inside
74+ the **public ** folder, for better security and separation of components.
75+
76+ This means that you should configure your web server to "point" to your project's
77+ **public ** folder, and not to the project root.
78+
79+ Specifying the Document Root
80+ ============================
81+
82+ The best way is to set the document root to the **public ** folder in the server
83+ configuration::
84+
85+ └── example.com/ (project folder)
86+ └── public/ (document root)
87+
88+ Check with your hosting service provider to see if you can change the document root.
89+ Unfortunately, if you cannot change the document root, go to the next way.
90+
91+ Using Two Directories
92+ =====================
93+
94+ The second way is to use two directories, and adjust the path.
95+ One is for the application and the other is the default document root.
96+
97+ Upload the contents of the **public ** folder to **public_html ** (the default
98+ document root) and the other files to the directory for the application::
99+
100+ ├── example.com/ (for the application)
101+ │ ├── app/
102+ │ ├── vendor/ (or system/)
103+ │ └── writable/
104+ └── public_html/ (the default document root)
105+ ├── .htaccess
106+ ├── favicon.ico
107+ ├── index.php
108+ └── robots.txt
109+
110+ See
111+ `Install CodeIgniter 4 on Shared Hosting (cPanel) <https://forum.codeigniter.com/showthread.php?tid=76779 >`_
112+ for details.
113+
114+ Adding .htaccess
115+ ================
116+
117+ The last resort is to add **.htaccess ** to the project root.
118+
119+ It is not recommended that you place the project folder in the document root.
120+ However, if you have no other choice, you can use this.
121+
122+ Place your project folder as follows, where **public_html ** is the document root,
123+ and create the **.htaccess ** file::
124+
125+ └── public_html/ (the default document root)
126+ └── example.com/ (project folder)
127+ ├── .htaccess
128+ └── public/
129+
130+ And edit **.htaccess ** as follows:
131+
132+ .. code-block :: apache
133+
134+ <IfModule mod_rewrite.c>
135+ RewriteEngine On
136+ RewriteRule ^(.*)$ public/$1 [L]
137+ </IfModule>
138+
139+ <FilesMatch "^\.">
140+ Require all denied
141+ Satisfy All
142+ </FilesMatch>
0 commit comments