CodeIgniter 4 separates its public entry point from application code and writable runtime data. The hosting document root should follow that separation.
IN THIS ARTICLE
Check access and requirements
Confirm the PHP and extension requirements for the supported CodeIgniter release. Check whether the account allows a custom domain document root or a vendor-documented shared-hosting layout.
01 Set a safe document root for CodeIgniter 4
Prepare the project in a directory that is not entirely exposed to visitors. Keep the current application package and its dependency metadata together.
Point the website document root to
publicwhere the panel permits it. Keep the application, system or vendor files and writable data outside direct web access.If the public folder must be separated from the project, follow the CodeIgniter shared-hosting deployment instructions and update the framework path references consistently. Do not simply copy every private directory into the public website.
Configure the web server rewrite behavior for the selected deployment. Check both the homepage and a non-homepage route.
Set production configuration and remove installation or diagnostic files that are not part of the finished application.
02 Example: choose the public directory in the hosting panel
Assume your CodeIgniter project is stored at /home/ACCOUNT/apps/customer-portal. The domain settings should expose its public child directory. These are illustrative form values; replace ACCOUNT and the project location with the paths assigned to your service.
Domain: portal.example.com
Project directory: /home/ACCOUNT/apps/customer-portal
Document root: /home/ACCOUNT/apps/customer-portal/public
Public entry file: public/index.php
The app, vendor and writable directories stay with the private project. Test a nested route as well as a real image or stylesheet. If the panel does not allow this document root, use the supported two-directory deployment method with correct bootstrap paths or ask for the required mapping.
Expected result: The application and assets load at the intended hostname. Requests for /.env and private logs cannot return their contents, and the entire project has not been exposed to fix one missing file.
Confirm the expected result
Request a nested application route and an actual static asset. Confirm direct requests for environment files, writable logs and private application files cannot reveal their contents.
Resolve setup problems
A missing bootstrap file usually means the moved public entry point references the wrong project path. Fix that path instead of making the whole application public.
A common question
Can I hide the private folders only with a guessed .htaccess rule?
Use the supported directory layout first. Access rules are an additional control and differ between Apache-compatible hosting and other web servers.