CodeIgniter is a powerful PHP framework for rapid development. It is an opensource PHP framework build by developers for developers to create web application faster. CodeIgniter 3 is the latest framework available and CodeIgniter 2 is legacy PHP framework.

This tutorial will help you to install CodeIgniter PHP framework on Ubuntu 16.04 Xenial LTS systems.

Step 1 – Prerequsities

Login to your Ubuntu 16.04 system vis desktop or ssh. CodeIgniter required PHP to be installed, MySQL as the database server and Apache/Nginx as the web server. Use one the following tutorial to install LAMP server on your system

Step 2 – Download CodeIgniter

Download the latest version of CodeIgniter from its official GitHub release page. You can use following commands to download CodeIgniter 3.1.9 on your system.

cd /var/www
wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.9.zip

Extract the archive on your local system and place directory for document root with proper naming.

unzip 3.1.9.zip
mv CodeIgniter-3.1.9 CodeIgniter

Step 3 – Create Database

Now, create a MySQL database for your CodeIgniter application. I am running MySQL 5.7 server on my machine. Connected to MySQL with root user then create database and user with the following queries.

mysql> CREATE DATABASE codeigniter;
mysql> GRANT ALL ON codeigniter.* to 'dbuser'@'localhost' IDENTIFIED BY '_password_';
mysql> FLUSH PRIVILEGES;
mysql> quit

Ater creating database, edit the CodeIgniter database configuration in text editor and update the database settings as per your environments.

vi application/config/database.php
$db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '_password_',
        'database' => 'codeigniter',
        'dbdriver' => 'mysqli',
        'dbprefix' => 'tec_',

Step 4 – Setup CodeIgniter on Ubuntu

Now you need to configure the base URL for your application. For this tutorial, I am using www.example.com domain for configuration. You can choose localhost or any valid domain name of your choice.

Edit config.php file in text editor:

vi application/config/config.php

and update base_url as following:

$config['base_url'] = 'http://www.example.com/';

Step 5 – Setup Apache for CodeIgniter

For this tutorial, I’m using Apache web server on my Ubuntu system. Create a new VirtualHost configuration file:

vi /etc/apache2/sites-available/codeigniter.conf

Add following content with proper server name, alias:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/CodeIgniter
    <Directory /var/www/CodeIgniter>
          Allowoverride All
    </Directory>
</VirtualHost>

Save the Apache VirtualHost configuration file. Now use the a2enmod command to enable newly created CodeIgniter VirtualHost. Also, restart Apache service to apply changes.

sudo a2enmod codeigniter
sudo systemctl restart apache2

Step 6 – Testing

All done. You can access your CodeIgnator application in your favorite web browser with the configured domain name.

 http://www.example.com/

By default, you will the screen like below.

Install CodeIgniter on Ubuntu

Let’s start developing with CodeIgniter.

The post How to Install CodeIgniter on Ubuntu 16.04 (Xenial) appeared first on TecAdmin.