Atlantic.Net Blog

How to Install CodeIgniter PHP Framework on Debian 10

CodeIgniter is a free and open-source PHP MVC Framework used for building websites in PHP. It is a very powerful framework that allows you to easily create full-featured web applications. CodeIgniter provides a set of useful libraries used for performing various operations like sending emails, uploading files, managing sessions, and more. Lightweight but powerful, CodeIgniter enables developers to write their applications much more quickly.

In this tutorial, we will explain how to install the CodeIgniter PHP Framework on Debian 10.

Prerequisites

  • A fresh Debian 10 VPS on the Atlantic.net Cloud Platform
  • A root password configured on your server

Step 1 – Create an Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing Debian 10 as the operating system with at least 1GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your Debian 10 server, run the following command to update your base system with the latest available packages.

apt-get update -y

Step 2 – Install LAMP Stack

First, you will need to install the Apache web server, MariaDB server, PHP, and other required packages in your system. You can install all of them by running the following command:

apt-get install apache2 mariadb-server libapache2-mod-php php php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath unzip git wget nano -y

Once all the packages are installed, start the Apache and MariaDB services and enable them to start at system reboot with the following command:

systemctl start apache2
systemctl start mariadb
systemctl enable apache2
systemctl enable mariadb

Step 3 – Configure the MariaDB Database

Next, you will need to create a database and user for CodeIgniter. First, log in to MySQL shell with the following command:

mysql

Once logged in, create a user and database with the following command:

CREATE USER 'codeigniter'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE codeigniterdb;

Next, grant all the privileges to the codeigniter database with the following command:

GRANT ALL ON codeigniterdb.* to 'codeigniter'@'localhost';

Next, flush the privileges and exit from the MariaDB console with the following command:

FLUSH PRIVILEGES;
EXIT;

Step 4 – Install and Configure CodeIgniter

First, download the latest version of CodeIgniter from the Git repository with the following command:

wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.11.zip

Once downloaded, unzip the downloaded file to the Apache web root directory:

unzip 3.1.11.zip
mv CodeIgniter-3.1.11 /var/www/codeigniter

Next, change the directory to /var/www/codeigniter and edit the database configuration file:

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

Define your database settings as shown below:

$db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'codeigniter',
        'password' => 'password',
        'database' => 'codeigniterdb',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',

Save and close the file then edit the config.php file and define your application URL:

nano application/config/config.php

Change the following line with your desired domain name:

$config['base_url'] = 'codeigniter.example.com';

Save and close the file then give proper ownership and permission with the following command:

chown -R www-data:www-data /var/www/codeigniter
chmod -R 755 /var/www/codeigniter

Once you are done, you can proceed to the next step.

Step 5 – Configure Apache for CodeIgniter

Next, you will need to create an Apache virtual host configuration file to serve the CodeIgniter application.

You can create it with the following command:

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

Add the following lines:

<VirtualHost *:80>
    ServerName codeigniter.example.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/codeigniter
    ErrorLog /var/log/apache2/codeigniter-error_log
    CustomLog /var/log/apache2/codeigniter-access_log combined
    <Directory /var/www/codeigniter>
            Require all granted
    </Directory>
</VirtualHost>

Save and close the file, then enable the virtual host configuration file with the following command:

a2ensite codeigniter.conf

Next, restart the Apache service to apply the changes:

systemctl reload apache2

Step 6 – Access CodeIgniter

At this point, CodeIgniter is installed and configured with Apache. Now, open your web browser and access the URL http://codeigniter.example.com. You should see your CodeIgniter application in the following screen:

Conclusion

Congratulations! You have successfully installed CodeIgniter Framework with Apache on Debian 10. For more information about how to use this PHP web application framework visit the CodeIgniter documentation page. Get started with CodeIgniter today on a Debian 10 VPS with VPS Hosting from Atlantic.Net!

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year