CodeIgniter is an open-source PHP framework for developers who need a simple and elegant tool to create dynamic web applications. It has a rich set of functionality that facilitates a fast web development process.

Features of CodeIgniter

  • Nearly Zero Configuration as most of the things are set up in CodeIgniter.
  • Model View Controller-based system.
  • Full-featured database classes with support for several platforms.
  • Form and data validation.
  • Clear Documentation.
  • Lightweight and exceptional performance 
  • Session Management.

Setup Server requirements

  • PHP version 7.3 or newer is required, with the *intl* extension and *mbstring* extension installed.
  • php-json, php-mysqlnd, php-xml PHP extensions should be enabled
  • Install libcurl package to use CURL request
  • Supported database, these include MySQL, PostgreSQL, SQLite3, and MSSQL

In this guide, I will show you how to install and use Codeigniter on KDE Neon / Kubuntu Linux systems.

Install Codeigniter on KDE Neon / Kubuntu

There are dependencies required to run Codeigniter.

  • Apache/Nginx Server
  • MySQL/MariaDB database server
  • PHP Programming language

Step 1. Install Apache Server on KDE Neon / Kubuntu

Update your cache index using the following command

### KDE Neon ###
sudo apt update && sudo pkcon update -y

### Kubuntu ###
sudo apt update && sudo apt upgrade -y

Next, install the Apache webserver using the following command.

sudo apt install apache2 -y

Check Apache status by running the following command

$ systemctl status apache2
 apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-03-19 16:58:06 EAT; 12s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 2747 (apache2)
      Tasks: 55 (limit: 4572)
     Memory: 4.9M
     CGroup: /system.slice/apache2.service
             ├─2747 /usr/sbin/apache2 -k start
             ├─2748 /usr/sbin/apache2 -k start
             └─2749 /usr/sbin/apache2 -k start

Step 2. Install MySQL Database Server on KDE Neon / Kubuntu

To install MySQL, use the following command.

sudo apt install -y mysql-server

Then run the post-installation script to set the password for the database server.

sudo mysql_secure_installation 

Select the level of the password you want then type in the new password.


Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

Type y and press Enter to set the other settings in their default state.

Step 3. Install PHP on KDE Neon / Kubuntu

To install PHP and the extensions required, use the following command

sudo apt install -y php php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-intl

Check version using

$ php -version
PHP 7.4.3 (cli) (built: Mar  2 2022 15:36:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Then restart Apache to make it compatible with PHP

sudo /etc/init.d/apache2 restart

Step 4: Install CodeIgniter on KDE Neon / Kubuntu

4.1: Manual Installation of CodeIgniter

Install Curl if you do not have it using the following command.

sudo apt install curl -y

To install CodeIgniter, use the following command to download the file from GitHub Release Page.

LATEST_VER=$(curl -s https://api.github.com/repos/codeigniter4/CodeIgniter4/releases/latest|grep tag_name | cut -d '"' -f 4)
wget https://github.com/codeigniter4/framework/archive/refs/tags/$LATEST_VER.tar.gz -O CodeIgniter-${LATEST_VER}.tar.gz

Extract and move the file with proper naming using the following commands.

tar xvf CodeIgniter-${LATEST_VER}.tar.gz && rm -f CodeIgniter-${LATEST_VER}.tar.gz
mv framework-*/ CodeIgniter

4.2: Install CodeIgniter using PHP Composer

Install composer on your system using the following command

curl -sS https://getcomposer.org/installer | php

Move the composer to file to a new directory say /usr/local/bin and set permissions to execute the file using the following commands.

mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

Run the following command to create a CodeIgniter application.

composer create-project codeigniter4/appstarter CodeIgnterApp

It will create a CodeIgniterApp folder

Step 5: Configure Database

Login as a root user to My SQL console using the password that you set

$ sudo mysql -u root -p
CREATE USER 'codeigniter'@'localhost' IDENTIFIED BY 'StrongPassword';
CREATE DATABASE codeigniter;
GRANT ALL ON codeigniter.* to 'codeigniter'@'localhost';
FLUSH PRIVILEGES;
EXIT;

We will set the database connection details using a .env file that allows us to edit only the details that we want to change with a specific format

Use the following commands to copy then open the new environment file.

cp CodeIgniter/env CodeIgniter/.env
vim CodeIgniter/.env

Then set the environment

#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------
CI_ENVIRONMENT = development

Set the database connection

#--------------------------------------------------------------------
# DATABASE
#--------------------------------------------------------------------

database.default.hostname = localhost
database.default.database = codeigniter
database.default.username = codeigniter
database.default.password = StrongPassword
database.default.DBDriver = MySQLi

Next is to configure the CodeIgniter base URL to access it via browser. Set like below. You can change the domain.

app.baseURL = 'http://code.example.com'

Once done with all configurations, Save the file and quit Vim usingesckey they typing :wq!.

Move the CodeIgniter file to /srv.

sudo mv CodeIgniter /srv

Step 6: Configure Apache for CodeIgniter

Set Permissions for the /srv/CodeIgniter directory.

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

Use the following command to create a new virtual host.

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

Copy the content. Edit the details to match what you want.

<VirtualHost *:80>
    ServerName code.example.com
    ServerAlias www.code.example.com
    ServerAdmin [email protected]
    DocumentRoot /srv/CodeIgniter/public
    ErrorLog /var/log/apache2/codeigniter-error_log
    CustomLog /var/log/apache2/codeigniter-access_log combined
    <Directory /srv/CodeIgniter/public>
	Require all granted
        AllowOverride All
        Options +Indexes
    </Directory>
</VirtualHost>

Enable the newly created virtual host and restart the server to apply the changes using the following command

sudo a2ensite codeingiter.conf
sudo systemctl restart apache2

Open your web browser and type the URL http:code.example.com, you will be redirected to the CodeIgniter dashboard as shown on the following page:

Conclusion

From this guide, you have learned how to install Codeigniter on KDE Neon|Kubuntu system using the Manual Installation and the PHP Composer. You have configured the Database Server and the Web Server for the CodeIgniter application. You can now create dynamic web applications using Codeigniter in a fast process.

LEAVE A REPLY

Please enter your comment!
Please enter your name here