CodeIgniter 4 (CI4) is a lightweight PHP framework with a small footprint, excellent documentation, and a gentle learning curve. It is ideal for developers who want a fast, simple MVC framework without heavy dependencies. This guide deploys CodeIgniter 4 on Ubuntu 26.04 LTS with Nginx and PHP 8.4.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS with Nginx, PHP 8.4-FPM, and MySQL
- Composer installed globally
Step 1 – Create a New CI4 Project
cd /var/www
sudo composer create-project codeigniter4/appstarter myci4app
sudo chown -R www-data:www-data /var/www/myci4app
Step 2 – Configure the Environment
cp /var/www/myci4app/env /var/www/myci4app/.env
nano /var/www/myci4app/.env
Set:
CI_ENVIRONMENT = production
app.baseURL = 'https://example.com/'
app.forceGlobalSecureRequests = true
Step 3 – Configure Database
In .env:
database.default.hostname = localhost
database.default.database = myci4db
database.default.username = ci4user
database.default.password = CI4Pass2026!
database.default.DBDriver = MySQLi
Step 4 – Set Up Nginx
sudo nano /etc/nginx/sites-available/myci4app
Add:
server {
listen 80;
server_name example.com;
root /var/www/myci4app/public;
index index.php;
location / { try_files $uri $uri/ /index.php?$args; }
location ~ .php$ {
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo ln -s /etc/nginx/sites-available/myci4app /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Step 5 – Set Permissions
sudo chmod -R 755 /var/www/myci4app
sudo chmod -R 777 /var/www/myci4app/writable
Step 6 – Run Migrations
cd /var/www/myci4app && php spark migrate
Step 7 – Test the Application
Visit http://example.com. You should see the CodeIgniter 4 welcome page.
Conclusion
CodeIgniter 4 is deployed on Ubuntu 26.04 LTS. Its spark CLI tool lets you create controllers, models, and migrations rapidly. Add SSL with Certbot and configure a Redis cache for session storage in production.