HugeServer Knowledgebase

How to install CodeIgniter with Apache, PHP 7.1, and MariaDB 10.2 on Ubuntu 16.04

Introduction

CodeIgniter is an Open-Source web application framework written in PHP which is very small in size but yet very powerful. CodeIgniter’s main purpose is to enable people to write their own applications much faster and easier by providing a set of useful libraries for most common tasks. it’s based on Mode-View-Controller (MVC) to approach a great separation of logic from presentation.
 
CodeIgniter Logo
 

Install Apache

First of all, you need to issue the following command to update your repository list:

apt-get update

Then you can install Apache 2 easily using “apt” with the following command:

apt-get install apache2

After the installation process is finished you can use the commands below to start your Apache service and make it run at startup:

systemctl start apache2

systemctl enable apache2

Install PHP 7.1

PHP 7.1 is not provided by the official repository so you have to add “PPA” repo in order to install it easily.

First, install Python Software Package with the following command:

apt-get install python-software-properties

Now you can add the preferred repository:

add-apt-repository ppa:ondrej/php

Update your repository list to fetch the latest packages with the command below:

apt-get update

execute the command below to easily install PHP 7.1 and the needed extensions:

apt-get install php7.1 php7.1-xml php7.1-mbstring php7.1-mysql php7.1-json php7.1-curl php7.1-cli php7.1-common php7.1-mcrypt php7.1-gd libapache2-mod-php7.1 php7.1-zip

Install MariaDB 10.2 (Latest)

At the time of the writing, 10.2 is the latest stable version of MariaDB.
First of all, you need to install the Software properties package:

apt-get install software-properties-common

Import the signing key with the following command:

apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

Now you can add the MariaDB repository with the command below:

add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.2/ubuntu xenial main'

Install MariaDB-Server package:

apt-get install mariadb-server

And after the installation, don’t forget to start and enable the service:

systemctl start mariadb

systemctl enable mariadb

Creating Database

First of all, we need to do some initial configuration for MariaDB.
Run the Mysql installer script with the following command:

mysql_secure_installation

Set a password for the “root” user and answer all other question with “y”
Login to root user with the following command:

mysql -u root -p

Now we can create our database with the command below (Make sure to replace the red parts with your preferred values):

create database HS;

grant all privileges on *.* to 'username'@'localhost' identified by 'password';

flush privileges;

Download CodeIgniter

Now we are going to download the CodeIgniter from the official website in our DocumentRoot:

wget https://codeload.github.com/bcit-ci/CodeIgniter/zip/3.1.7 -P /var/www/html/

You need to extract the source files from the “zip” file that you just download, so install “Unzip” first:

apt-get install unzip

Unzip the downloaded file with the following command:

unzip /var/www/html/3.1.7 -d /var/www/html/

Rename the extracted directory as below:

mv /var/www/html/CodeIgniter-3.1.7 /var/www/html/codeigniter

Set the Database

In CodeIgniter configuration files there is a “database.php” file which you can set your Databases information in it:

nano /var/www/html/codeigniter/application/config/database.php

Find the following block in that file, and enter your Database information:

$db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'username',
        'password' => 'password',
        'database' => 'HS',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
);

Set the correct DocumentRoot

Open the Apache configuration file:

nano /etc/apache2/sites-available/000-default.conf

Find the line that refers to:

DocumentRoot "/var/www/html"

and change it like below:

DocumentRoot "/var/www/html/codeigniter/"

Then save and exit.

Restart Apache to take effect:

systemctl restart apache2

Set the Permissions

Execute the following command one by one to set the proper permissions:

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

Test if everything works fine

Now you can open your browser and see your public IP address or your Domain through it.

CodeIgniter Welcome Page
 
You can check out CodeIgniter official website for more information and news!

Was this tutorial helpful?

Thank you for your vote.Thank you for your vote.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*