Installing CodeIgniter PHP Framework on Ubuntu 18.04 / Debian 9

(: November 21, 2018)

CodeIgniter is an open source Application Development Framework for building websites using PHP. The goal of CodeIgniter is to enable you to develop projects much faster without writing code from scratch. It gives you a rich set of libraries for commonly needed tasks, simple interface and logical structure to access these libraries.

Installing CodeIgniter PHP Framework on Ubuntu 18.04 / Debian 9

The steps for installing the CodeIgniter PHP Framework on Ubuntu 18.04 / Debian 9 are a bit straightforward. Only that there are below few dependencies/Prerequisites:

  • MySQL / MariaDB database server
  • Apache / Nginx web server
  • PHP

Step 1: Install PHP on Ubuntu 18.04 / Debian 9

Start with the installation of PHP on Ubuntu 18.04 & Debian 9 from apt repository:{text-align:left} img{margin:0 auto 0 0}
sudo apt install php php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath

If planning to use Nginx web server, you need to install php-fpm

sudo apt install php-fpm

Confirm PHP version:

# php -v
PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

Step 2: Install and Configure Database

In this section, we’ll install and configure Database server for CodeIgniter. You have an option to use MySQL or MariaDB database server. Refer to our previous guides for the installation of MariaDB/MySQL on Ubuntu & Debian.

How to Install MariaDB 10.3 on Debian 9 / Debian 8

Install MariaDB 10.3 on Ubuntu 18.04 and CentOS 7

For MySQL Database server, check:

How to Install MySQL 8.0 on Ubuntu 18.04 / 16.04

After installing the database server, create a database and user for CodeIgniter.

Login as root user to MySQL console

$ mysql -u root -p

CREATE USER 'codeigniter'@'localhost' IDENTIFIED BY 'StrongPassword';
CREATE DATABASE codeigniter;
GRANT ALL ON codeigniter.* to 'codeigniter'@'localhost';

Step 3: Install and Configure CodeIgniter

Once you have the database server installed and database created. You can proceed to install and configure CodeIgniter.

Download the latest release of CodeIgniter from Github page.

export LATEST_VER="3.1.9"
tar xvf ${LATEST_VER}.tar.gz
mv CodeIgniter-${LATEST_VER} CodeIgniter
rm {LATEST_VER}.tar.gz

Edit CodeIgniter database configuration file to set database credentials:

vim CodeIgniter/application/config/database.php

Set the configuration parameters like below:

'hostname' => 'localhost',
        'username' => 'codeigniter',
        'password' => 'StrongPassword',
        'database' => 'codeigniter',

Below is a full configuration screenshot:

Next is to configure CodeIgniter base URL for accessing via your web browser.

vim CodeIgniter/application/config/config.php

Set like below:

$config['base_url'] = '';

When done with the configurations, move the CodeIgniter folder to /srv

sudo mv CodeIgniter /srv/

Step 4: Install and Configure Apache Web server

Install the apache2package by running:

sudo apt -y install apache2 libapache2-mod-php

Set proper permissions for /srv/CodeIgniter

sudo chown -R www-data:www-data /srv/CodeIgniter

Create an apache configuration file for CodeIgniter

sudo vim /etc/apache2/sites-enabled/codeigniter.conf


<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /srv/CodeIgniter
    ErrorLog /var/log/apache2/codeigniter-error_log
    CustomLog /var/log/apache2/codeigniter-access_log combined
    <Directory /srv/CodeIgniter>
	Require all granted

Restart apache2 service

sudo systemctl restart apache2

If you access from your browser, you should get a page like below:

This page signifies successful installation of CodeIgniter on Ubuntu 18.04 / Debian. You can start your development with CodeIgniter and refer to the User guide manual for more learning.{text-align:left} img{margin:0 auto 0 0}

Related Posts