A CodeIgniter application runs well on cPanel hosting, as long as the domain points at the application’s public folder and not at the project root. That is the one thing almost everybody gets wrong: the rest (the database, the .env file, the writable folders) is configuration. This article covers CodeIgniter 4, the current one; there is a note on 3 at the end.
CodeIgniter 4 separates what a visitor may request (the public folder) from what should never be requested (app, system and writable). If the domain points at the root, the site shows a folder listing or an error, and the worst case is leaving your configuration in plain view.
From your computer to cPanel, step by step
| 1 |
Check the PHP version. Each CodeIgniter 4 release states its minimum PHP version in the official documentation. Pick it in Select PHP Version for the site’s folder: which PHP version to use.
|
|
| 2 |
Upload the project OUTSIDE the public folder. For example to /home/ACCOUNT/app-ci, next to public_html. If you use Composer, run composer install there and upload the result: Composer on shared hosting.
|
|
| 3 |
Point the domain at the public folder. With an addon domain or a subdomain you choose the folder when you create it: enter /home/ACCOUNT/app-ci/public. For the main domain, check in cPanel’s domains screen whether it lets you change the folder; if not, use a subdomain for the application.
|
|
| 4 |
Create the .env file. The project ships a template called env, without the dot. Copy it to .env in the project root and edit it (see the table below).
|
|
| 6 |
Make the writable folder writable. It is where the application keeps logs, sessions and cache. If it cannot write, the site errors on the very first request.
|
|
What goes in .env
| Line |
What it is for |
| CI_ENVIRONMENT = production |
Puts the application in production mode: errors stop showing to visitors. In development details appear that you must not expose. |
| app.baseURL = 'https://yourdomain.tld/' |
The site address, with the trailing slash and in https. A wrong address breaks links and forms. |
| database.default.hostname |
Usually localhost. Database and user names carry the account prefix. |
| database.default.database, .username, .password |
The details you created in cPanel. The password lives here and never in the code. |
| database.default.DBDriver = MySQLi |
The engine. For PostgreSQL the value is different, and the pgsql extension has to be switched on in Select PHP Version. |
|
The .env file must be out of the browser’s reach. With the domain pointing at the public folder, it is. If somebody pointed the domain at the project root, anyone can request .env and walk away with your passwords. Try opening that address: it must give 403 or 404. See keeping passwords out of your code.
|
|
404 on every page except the home page? Friendly links need the rewrite rules in the .htaccess that comes inside the public folder. If it was not uploaded (names starting with a dot are hidden), the application only answers with index.php in the address. See .htaccess for PHP projects.
|
|
CodeIgniter 3? It is older and runs on older PHP versions. The practical difference: index.php sits in the project root, the configuration is in application/config, and the system folder should stay outside the public folder. The idea is the same: code is never within the browser’s reach. If the site is old and nobody updates it, plan to replace it.
|
|
Uploaded the application and all you see is an error? Send us the address and the last line of the log in writable/logs.
Open a support ticket
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 321,75 MT/mo (3-year plan, with coupon) See plans |