
Most CodeIgniter installs fail for boring reasons. The framework itself is rarely the problem. The usual causes are a document root pointing at the wrong folder, a missing intl extension, or a writable/ directory the web server can’t touch. Those mistakes cost people an evening, and they are easy to avoid.
Ubuntu 26.04 LTS adds one more wrinkle. It ships PHP 8.5 in its default repositories, and the release went out in April 2026. CodeIgniter’s own documentation says PHP 8.5 needs CodeIgniter 4.7.0 or later. Many older tutorials still pin PHP 7.x or 8.1, and copying their commands onto a fresh 26.04 server produces confusing errors. The current CodeIgniter release is 4.7.6, and the project requires PHP 8.2 or newer.
This guide is a production-minded walkthrough. It installs CodeIgniter 4 on Ubuntu 26.04 with Nginx, PHP-FPM and Composer. It also covers a MySQL database, file permissions, firewall rules, HTTPS, performance tuning and a long troubleshooting section. The commands work on a VPS, a cloud instance or a local virtual machine. Where Debian or AlmaLinux differ, the differences are noted.
What You Need Before Starting
The requirements are modest. The habits around them matter more than the specs.
- A fresh Ubuntu 26.04 LTS server with sudo access. A fresh install is easier to reason about than a server with years of leftovers.
- At least 1 GB of RAM. Composer can run out of memory on smaller machines, so add swap if you go below that.
- A domain name pointing at the server, if you want HTTPS. Without one, test with the server IP.
- A non-root user. Never run Composer as root.
Confirm the release first:
lsb_release -a
uname -r
Then update everything:
sudo apt update && sudo apt full-upgrade -y
sudo reboot
Reboot if a kernel update came in. Debugging a new stack on top of a half-updated system wastes time.
Why CodeIgniter 4 on Nginx and PHP-FPM
CodeIgniter 4 is a small framework. The official site describes it as a download of about 1.1 MB, which is part of why it still gets used for APIs, admin panels and legacy modernisation work. That small footprint pairs well with Nginx and PHP-FPM, which is the standard stack for busy PHP sites.
Apache works fine too. Nginx tends to use less memory under concurrent load, and its configuration is easy to read. The rest of this guide uses Nginx. An Apache note appears later.
Step 1: Install Nginx
sudo apt install nginx -y
sudo systemctl enable --now nginx
systemctl status nginx --no-pager
Visit the server IP in a browser. The default Nginx welcome page confirms the web server works. If it doesn’t load, check the firewall before blaming Nginx. That is covered in the security section.
Step 2: Install PHP 8.5 and the Required Extensions
On Ubuntu 26.04, the stock repositories carry PHP 8.5, so no third-party PPA is needed. Install the FPM package by name rather than the generic php metapackage. The metapackage can pull in Apache you didn’t ask for.
sudo apt install php8.5-fpm php8.5-cli php8.5-intl php8.5-mbstring \
php8.5-xml php8.5-curl php8.5-mysql php8.5-zip php8.5-gd unzip curl -y
Why these extensions? CodeIgniter’s requirements list intl, mbstring, json and curl among others, and the documentation notes that you may need to enable intl and curl in php.ini. On Ubuntu the packages enable them automatically. mysql covers the database driver, zip and unzip help Composer, and gd handles image work.
Verify:
php -v
php -m | grep -Ei 'intl|mbstring|curl|mysqli|xml'
systemctl status php8.5-fpm --no-pager
On a typical install the version reads 8.5.x. The FPM socket lives at /run/php/php8.5-fpm.sock. Remember that path, because the Nginx configuration needs it.
Debian and AlmaLinux note: on Debian, use the PHP version your release provides, or Ondřej Surý’s repository for newer ones. On AlmaLinux, enable Remi’s repository and install php-fpm, php-intl and php-mbstring with dnf. The socket path and service name differ, so check with systemctl list-units | grep fpm.
Step 3: Install Composer
Composer is the recommended way to install CodeIgniter, because it makes updates simple. CodeIgniter requires Composer 2.0.14 or later. Ubuntu’s packaged Composer is usually recent enough, but the official installer is the safest source.
cd /tmp
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
composer --version
The official site publishes a SHA-384 hash for the installer. On a production machine, take the extra minute to verify it. Running a downloaded script blindly is a habit worth dropping.
Step 4: Create the Project with Composer
Choose the directory carefully. A common choice is /var/www/example.com. The official guidance is to run the create-project command in the folder above your project root.
sudo mkdir -p /var/www
sudo chown $USER:$USER /var/www
cd /var/www
composer create-project codeigniter4/appstarter example.com
This pulls the application starter. Composer resolves the framework version for you, which on a current install should be the 4.7.x series. Check it:
cd /var/www/example.com
php spark --version
spark is CodeIgniter’s command-line tool. It will be useful again shortly.
Manual Download as an Alternative
The documentation also supports a manual download. It works, but updates become a manual job. For anything beyond a throwaway test, Composer is the better habit.
Step 5: Configure the Environment File
The starter ships with a file called env. Copy it to .env:
cp env .env
nano .env
Set at least these values:
CI_ENVIRONMENT = production
app.baseURL = 'https://example.com/'
Leave CI_ENVIRONMENT as production on any public server. In development mode, CodeIgniter shows detailed error pages, including file paths and sometimes configuration hints. Those are a gift to attackers. Switch to development only on a local machine.
Database credentials go in the same file:
database.default.hostname = localhost
database.default.database = ci_app
database.default.username = ci_user
database.default.password = Use-A-Long-Random-Password
database.default.DBDriver = MySQLi
Never commit .env to Git. Add it to .gitignore if it isn’t already there.
Step 6: Set Up the Database
Ubuntu 26.04 offers MySQL 8.4 in its repositories. MariaDB is a fine alternative.
sudo apt install mysql-server -y
sudo mysql_secure_installation
Then create a dedicated database and user:
CREATE DATABASE ci_app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'ci_user'@'localhost' IDENTIFIED BY 'Use-A-Long-Random-Password';
GRANT ALL PRIVILEGES ON ci_app.* TO 'ci_user'@'localhost';
FLUSH PRIVILEGES;
Run it inside sudo mysql. Why a dedicated user? Because if the application is ever compromised, the damage stays inside one database. Using the root account in .env is one of the most common and most avoidable mistakes in small deployments.
Test the connection from the project:
php spark migrate:status
If it connects, you will see a migration table or a clean empty result. If not, jump to the troubleshooting section.
Step 7: Configure Nginx for CodeIgniter
This is the step where most installs go wrong. CodeIgniter 4 keeps its application code outside the web root. Only the public folder should be exposed. Point Nginx at public, not at the project folder.
Create the server block:
sudo nano /etc/nginx/sites-available/example.com
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.php index.html;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}
location ~ /\.(?!well-known) {
deny all;
}
location ~* \.(?:css|js|jpg|jpeg|png|gif|ico|svg|woff2?)$ {
expires 30d;
access_log off;
add_header Cache-Control "public";
}
}
A few details worth understanding. The try_files line sends unknown URLs to index.php, which is how clean routes like /products/42 work without index.php in the address. The dot-file rule blocks .env and .git from being served, while still allowing Let’s Encrypt validation under .well-known. The static asset block gives browsers a reason to cache files.
Enable the site and reload:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx
Always run nginx -t before reloading. A syntax error caught there is a minor annoyance. A failed reload on a live server is an outage.
Apache Alternative
For Apache with PHP-FPM, enable proxy_fcgi and rewrite, set DocumentRoot /var/www/example.com/public, and allow overrides for that directory. The public/.htaccess file shipped with CodeIgniter handles routing. PHP-FPM is not enabled in Apache by default, so wire it up deliberately.
Step 8: Set Permissions Correctly
CodeIgniter writes logs, cache, sessions and uploads to the writable directory. The web server user must be able to write there. On Ubuntu that user is www-data.
cd /var/www/example.com
sudo chown -R $USER:www-data .
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
sudo chmod -R 775 writable
sudo chmod g+s writable
The logic is simple. Your user owns the code. The www-data group can read it everywhere and write only to writable. Avoid chmod 777. It “fixes” the error and creates a security hole at the same time. Under SELinux on AlmaLinux, you will also need chcon or semanage fcontext for the writable path, otherwise permissions look right and writes still fail.
Step 9: Open the Firewall
Ubuntu includes UFW. Allow SSH before enabling it, or you will lock yourself out.
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status verbose
Nginx Full opens ports 80 and 443. MySQL should never be exposed publicly. Keep it bound to localhost, which is the default on Ubuntu. Add fail2ban if the server is internet-facing:
sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban
Step 10: Enable HTTPS with Let’s Encrypt
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
sudo systemctl list-timers | grep certbot
Certbot edits the Nginx config, adds the redirect and installs a renewal timer. Confirm renewal works with sudo certbot renew --dry-run. Certificates that silently expire are a classic Monday-morning surprise.
Afterward, make sure app.baseURL uses https://. Mixed content problems often trace back to that one line. In CodeIgniter, Config\App also has a forceGlobalSecureRequests option you can enable for HTTPS enforcement at the application level.
Verify the Installation
Open https://example.com/. The CodeIgniter welcome page should load. For a command-line check:
curl -I https://example.com/
tail -n 20 /var/www/example.com/writable/logs/log-$(date +%F).log
Then create a quick controller to prove routing works:
php spark make:controller Hello
Edit app/Controllers/Hello.php:
public function index()
{
return 'Server is working.';
}
Add a route in app/Config/Routes.php:
$routes->get('hello', 'Hello::index');
Request /hello. If it responds, then rewrites, PHP-FPM and the framework all work together. Delete the test route afterward.
Security Hardening for Production
Security work on a server is mostly about removing options. A few measures are worth the effort.
Keep the application outside the web root. The public folder approach does this for you. Do not point Nginx at the project root, ever.
Hide version information. In /etc/nginx/nginx.conf, set server_tokens off;. In /etc/php/8.5/fpm/php.ini, set expose_php = Off.
Add basic security headers. Inside the server block:
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
Use CodeIgniter’s built-in protections. CSRF protection, the Security filter, and output escaping with esc() should be on by default in forms and views. The framework provides context-sensitive escaping and CSP support, and ignoring them wastes real value.
Disable risky PHP functions if the application doesn’t need them. For example, set disable_functions = exec,passthru,shell_exec,system,proc_open,popen in php.ini. Test first, because some libraries do rely on them.
Patch regularly. CodeIgniter’s changelogs include security sections. Version 4.7.4, for instance, lists a security category in its release notes. Run composer update on a schedule, review the changelog, and test on staging before production. Enable unattended security updates for the OS:
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades
Deploy without dev dependencies. On production, run composer install --no-dev, as the official documentation advises. Fewer packages means a smaller attack surface.
Troubleshooting Common Errors
502 Bad Gateway
Nginx can’t reach PHP-FPM. Check that the service is running and that the socket path in the config matches the real one.
systemctl status php8.5-fpm
ls -l /run/php/
sudo tail -n 30 /var/log/nginx/example.com.error.log
A mismatch between php8.3-fpm.sock copied from an older tutorial and the actual php8.5-fpm.sock is a frequent cause on 26.04.
404 on Every Route Except the Home Page
The try_files directive is missing or malformed. Confirm it matches the block shown earlier, then run sudo nginx -t and reload.
“Class ‘Locale’ not found” or intl Errors
The intl extension is missing. Install it and restart FPM:
sudo apt install php8.5-intl -y
sudo systemctl restart php8.5-fpm
Permission Denied Writing to writable/
Check ownership and mode. SELinux can also block writes on AlmaLinux even when the mode looks right.
ls -ld writable writable/*
sudo -u www-data touch writable/test && echo OK
Remove the test file afterward.
Composer Memory Exhausted
Common on small VPS instances. Create temporary swap:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Then retry Composer. Disable the swap later if you don’t want it.
PHP Version Conflicts
A requirement error mentioning the PHP version usually means the CLI and FPM versions differ, or the framework is older than PHP. Check:
php -v
php-fpm8.5 -v
composer show codeigniter4/framework | head -n 5
If an older CodeIgniter release is installed, run composer update codeigniter4/framework to reach a build that supports PHP 8.5.
Database Connection Refused or Access Denied
Verify credentials by logging in manually:
mysql -u ci_user -p -h localhost ci_app
If that works but the app fails, check for stray whitespace or quotes in .env. If it fails, fix the grants.
Blank White Page
Production mode hides errors, which is correct, but it makes debugging confusing. Read the log first:
tail -f writable/logs/log-*.log
sudo tail -f /var/log/nginx/example.com.error.log
Do not switch a public site to development mode to see the error. Reproduce the problem on staging.
Base URL Redirect Loops
Behind a proxy or load balancer, the app may not realise it is on HTTPS. Configure trusted proxies in Config\App and make sure the proxy sends X-Forwarded-Proto.