How to Install CodeIgniter 4 PHP Framework on Ubuntu 20.04

CodeIgniter is an open-source PHP framework for building websites. It provides a platform for developers to build projects much faster because you don’t have to write code from scratch. The same also has enormous community support to offer different libraries. 

With CodeIgniter, you’re looking at a brilliant tool that helps you gain considerably more focus on the project as a user. The tool aids in reducing the amount of coding-related tasks. That being said, its overall mechanism helps enhance the creative section.

In simple words, CodeIgniter is like a catalyst that plays a pivotal role in improving the overall efficiency. What makes it more impressive is that it is entirely free to use.

Some noteworthy advantages of CodeIgniter include:

  • The tool is brilliant in error handling. Not just that, it can deal with bugs pretty much seamlessly.
  • CodeIgniter has amazing overall customizability. In fact, it is the sole open-source framework that offers ease of customization. 
  • Alongside being flexible and customizable, the levels of security it offers is top-notch. 
  • It features a user-friendly interface. Despite being home to such advanced features, it also boasts operational simplicity.
  • The tool is based on MVC or Method View Controller Model.
  • CodeIgniter offers better overall optimization.
  • It is known to support quick and seamless development.
  • The community support in CodeIgniter is also brilliant.
  • Offering hassle-free migration, CodeIgniter ensures trouble-free usage.

CodeIgniter 4 is the latest version available. In this article, we will help you figure out how to install CodeIgniter and how to use it on Ubuntu 20.04. So keep reading if you want to know more.


Before directly installing CodeIgniter, you need to set up a LAMP server first. LAMP stands for Linux, Apache, MySQL, and PHP. Also, as a usual practice, we’ll need to make sure that the system repositories are updated. Let’s review all of them in detail.

Checking For Repository Updates

First, check for any updates using the following command.


$ sudo apt update

Getting Apache Installed

Installing Apache Web server packages is no big deal. All you need to do is run the following command:

install apache

Once done, make sure to run Apache and verify the running status. For this, invoke the enable, start, and status command as you can see below.

Enable Input:

$ sudo systemctl enable apache2

Start Input: 

$ sudo systemctl start apache2

Status Input:

$ sudo systemctl status apache2

Installing MariaDB

MariaDB is a relational database management system created from MySQL. It is crucial to install it to get CodeIgniter ready on your system.

Execute the following command to install MariaDB:

install CodeIgniter on ubuntu

Once installation concludes, you can set the password for localhost. From there, you can also configure security settings. However, you’ll need to pass the following command inside the Terminal. Make sure you employ the best-fit configurations.


$ sudo mysql_secure_installation

Installing PHP On Your System

Just like Apache and MariaDB, getting PHP installed is also crucial. Here is how you can get the job done:

Step 1: Install the Required Dependency

Enter the following commands and install the required dependencies for PHP 8.0:

install CodeIgniter on ubuntu

Step 2: Restart Apache

Now, restart the Apache server so that the changes made get successfully applied.


$ sudo systemctl restart apache2

Step 3: Add More Dependencies

As soon as you’re done restarting Apache, add some other important dependencies.


add dependencies

Download and Install Curl

The final requisites include curl installation. Simply invoke the following command inside the Terminal:

$ sudo apt install curl

Installing and Creating a CodeIgniter Application

Now that all the prerequisites are sorted, it is time to install CodeIgniter on your system. To aid you to better understand the process, here we will provide you with an easy-to-digest guide.

Step 1: Installing Composer

Composer is a dependency manager for PHP(similar to how NPM works for Node.js). You can use the curl command and install the utility. Input:

install codeigniter and create apps

Step 2: Creating Igniter App using CodeIgniter

While you’re inside the Terminal, employ the following command to seamlessly create an igniter app.


$ composer create-project codeigniter4/appstarter CodeApps

Step 3: Configuring MariaDB for CodeIgniter

Start by invoking the following command:

$ sudo mysql -u root -p

From there, make the following alterations:

MariaDB [(none)]> CREATE DATABASE codeigniter4;
MariaDB [(none)]> GRANT USER 'dbuser'@'localhost' [The One IDENTIFIED BY] 'your_password';
MariaDB [(none)]> GRANT ALL ON codeigniter4.* to 'dbuser'@'localhost';
MariaDB [(none)]> quit

After that, edit the database configuration in the following manner:

config changes
'DBCollat' => 'utf8_general_ci',
'swapPre'  => '',
	'encrypt'  => false,
	'compress' => false,
	'strictOn' => false,
	'failover' => [],
	'port'     => 3306,

Step 4: Configuring the CodeIgniter Application

Here, you’re looking at the most critical step. Run the sudo nano command to edit App.php.


$ sudo nano app/Config/App.php

Next, update the baseURL to the domain. You should type in something like this:

public $baseURL = ‘

Also, make sure you alter the timezone for your application. Here is how to do it:

public $appTimezone = ‘UTC’

Step 5: Configure Apache server for CodeIgniter

To get the job done, simply use the following set of commands:

install CodeIgniter on ubuntu

Now add the following variable:

install CodeIgniter on ubuntu

Step 6: Restart Apache Server and Apply the Changes

The following commands will help you save the current modifications and restart the Apache server.


Getting CodeIgniter ready

And that’s how you get CodeIgniter ready on your system. Now you can seamlessly access your CodeIgniter app through the same domain. Yes, the one you’ve used earlier (

And with that we have successfully installed CodeIgniter and created a basic web app using the same software. We hope this session has been a valuable one for you.

If this guide helped you, please share it.

Leave a Reply
Related Posts