How to Install CodeIgniter on Ubuntu 24.04

In this tutorial, we will explain how to install CodeIgniter on Ubuntu 24.04 OS. CodeIgniter is a free and open-source PHP framework for building web applications and websites. CodeIgniter uses the MVC (Model-View-Controller) pattern for code organization and is one of the fastest PHP frameworks. The main characteristics of CodeIgniter are that it is flexible, provides a toolkit with rich libraries for database access, sessions, is secure, provides routing, rapid development, etc. In this tutorial, we will install CodeIgniter with the LAMP stack.

Installing CodeIgniter on Ubuntu 24.04 is straightforward, and it should take around 10 minutes. Let’s get started!

Prerequisites

  • A server running Ubuntu 24.04 OS
  • User privileges: root or non-root user with sudo privileges
  • A valid domain with pointed A record to the server

Step 1. Update the System

Before we start with the installation of CodeIgniter and the LAMP stack, we will update the system packages to their latest versions. Execute the following command:

sudo apt update -y && sudo apt upgrade -y

Step 2. Install the LAMP Stack

LAMP stack stands for Linux, Apache, MySQL, and PHP. CodeIgniter software cannot work without this stack, because without it, we cannot create a database, install CodeIgniter, and configure the domain name. First, we will install the Apache web server. To do that, execute the following command:

sudo apt install apache2 -y

Once installed start and enable the Apache service:

sudo systemctl start apache2 && sudo systemctl enable apache2

Check the status of the service:

sudo systemctl status apache2

You should get the following output:</p

root@host:~# sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: active (running) since Sat 2025-12-06 04:06:14 CST; 6s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 205270 (apache2)
Tasks: 55 (limit: 4602)
Memory: 5.2M (peak: 5.8M)
CPU: 149ms
CGroup: /system.slice/apache2.service

Next of the LAMP stack will be the PHP with its extensions. To install it execute the following command:

sudo apt install php libapache2-mod-php php-mysql php-cgi php-mysqli php-pear php-phpseclib php-mbstring php-zip php-gd php-curl php-common -y

Once installed execute the following command to check the PHP version:

php -v

You should get the following output:

root@host:~# php -v
PHP 8.3.6 (cli) (built: Jul 14 2025 18:30:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Last of the LAMP stack will be the MariaDB database service. To install it, execute the command below:

sudo apt install mariadb-server -y

Once installed start and enable the MariaDB service:

sudo systemctl start mariadb && sudo systemctl enable mariadb

Check the status of the service:

sudo systemctl status mariadb

You should get the following output:

root@host:~# sudo systemctl status mariadb
● mariadb.service - MariaDB 10.11.13 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
Active: active (running) since Sat 2025-12-06 04:09:29 CST; 20s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 208483 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 30378)
Memory: 78.7M (peak: 81.8M)
CPU: 1.117s
CGroup: /system.slice/mariadb.service

Step 3. Create CodeIgniter Database and User

To create the CodeIgniter database, database user and assign the privileges, log in to the MariaDB terminal and execute the following commands:

CREATE USER 'codeigniter'@'localhost' IDENTIFIED BY 'StrongPasswordHere';

CREATE DATABASE codeigniterDB;

GRANT ALL PRIVILEGES ON codeigniterDB.* TO 'codeigniter'@'localhost';

FLUSH PRIVILEGES;

EXIT;

Step 4. Install Composer

We need to install the Composer responsible for installing all the CodeIgniter components. To install Composer execute the following command:

curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

To check the Composer version execute the command bellow:

composer

You should receive the following output:

root@host:/var/www/html/codeigniter# composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 2.9.2 2025-11-19 21:57:25
.
.
.
.

Step 5. Install CodeIgniter

We will install the CodeIgniter using Composer into the Apache document root:

mkdir /var/www/html/codeigniter

cd /var/www/html/codeigniter

composer create-project codeigniter4/appstarter example-app

Next is to set the correct permissions:

chown -R www-data:www-data /var/www/html/codeigniter/

find . -type f -exec chmod 644 {} \;

find . -type d -exec chmod 755 {} \;

Once, the permissions are set, we can configure the env file. Open the following file:

sudo nano /var/www/html/codeigniter/example-app/env

Find these lines and adjust them according to the database credentials you set above.

#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------

CI_ENVIRONMENT = production

#--------------------------------------------------------------------
# APP
#--------------------------------------------------------------------

app.baseURL = YourDomainNameHere
# If you have trouble with `.`, you could also use `_`.
# app_baseURL = ''
# app.forceGlobalSecureRequests = false
# app.CSPEnabled = false

#--------------------------------------------------------------------
# DATABASE
#--------------------------------------------------------------------

database.default.hostname = localhost
database.default.database = ci4
database.default.username = codeigniter
database.default.password = codeigniterDB
database.default.DBDriver = MySQLi
database.default.DBPrefix =
database.default.port = 3306

Step 6. Create Apache Virtual Host File

Apache Configuration file for our CodeIgniter installation is necessary if we want to access it via a domain name. To create the file execute the following command:

sudo touch /etc/apache2/sites-available/codeigniter.conf

Open the file and paste the following lines of code

<VirtualHost *:80>
ServerName yourdomainhere.com
DocumentRoot /var/www/html/codeigniter/example-app/public/

<Directory /var/www/html/codeigniter/example-app>
AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Save the file and close it.

Enable the Apache configuration files for WordPress along with the rewrite module.

sudo a2enmod rewrite

sudo a2ensite codeigniter.conf

sudo a2dissite 000-default.conf

Check the Apache2 syntax:

apachectl -t

You should receive the following output:

root@host:/var/www/html/codeigniter# apachectl -t
Syntax OK

If the syntax is OK, restart the Apache service.

systemctl restart apache2

That’s it. Now you can access the CodeIgniter at http://yourdomainhere.com

Congratulations! You successfully installed CodeIgniter on Ubuntu 24.04 OS

If you liked this post on how to install CodeIgniter on Ubuntu 24.04, please share it with your friends on social networks or simply leave a reply below. Thanks.

Leave a Comment