CodeIgniter 4 is a lightweight, fast PHP framework ideal for developers who want a simple MVC structure without heavy overhead. This guide installs CodeIgniter 4 on Ubuntu 24.04 LTS with Nginx and PHP 8.3.

Tested and valid on:

  • Ubuntu 24.04 LTS

Prerequisites

  • Ubuntu 24.04 LTS server
  • Nginx, PHP 8.3-FPM installed
  • Composer installed

Step 1 – Create a New CodeIgniter 4 Project

Use Composer:

composer create-project codeigniter4/appstarter /var/www/ci4app

Step 2 – Set Permissions

Allow the web server to write logs and cache:

sudo chown -R www-data:www-data /var/www/ci4app
sudo chmod -R 755 /var/www/ci4app
sudo chmod -R 775 /var/www/ci4app/writable

Step 3 – Configure Environment

Copy and edit the environment file:

cd /var/www/ci4app
cp env .env
nano .env

Set the base URL and environment:

CI_ENVIRONMENT = production
app.baseURL = 'https://ci4.example.com/'

Step 4 – Configure Database

In .env, set the database credentials:

database.default.hostname = localhost
database.default.database = ci4db
database.default.username = ci4user
database.default.password = StrongPass123!
database.default.DBDriver = MySQLi

Step 5 – Configure Nginx

Create the Nginx server block:

sudo nano /etc/nginx/sites-available/ci4app

Add:

server {
    listen 80;
    server_name ci4.example.com;
    root /var/www/ci4app/public;
    index index.php;
    location / { try_files $uri $uri/ /index.php?$args; }
    location ~ .php$ {
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Enable and reload:

sudo ln -s /etc/nginx/sites-available/ci4app /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Step 6 – Run Migrations

Apply the default migrations:

cd /var/www/ci4app && php spark migrate

Step 7 – Add SSL

Secure with Let’s Encrypt:

sudo certbot --nginx -d ci4.example.com

Conclusion

CodeIgniter 4 is now deployed on Ubuntu 24.04 LTS. Its lightweight footprint and simple MVC architecture make it excellent for APIs and small to medium web applications.