In this article, we will have explained the necessary steps to install and configure CodeIgniter on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo
privileges. All the commands in this tutorial should be run as a non-root user.
CodeIgniter is one of the most popular PHP frameworks that was first released in 2006. The first developer of CodeIgniter was EllisLab which was then continued by the British Columbia Institute of Technology. Codeigniter 4 is the latest version available for application development.
Install CodeIgniter on Ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install LAMP Stack on Ubuntu.
CodeIgniter is built with PHP. You can host it like you would any other web app is written in PHP. So, you’re going to need to set Ubuntu up as either a LAMP server. If you haven’t done so already, use our traditional LAMP guide to set up Ubuntu to serve PHP before you continue.
Step 3. Download and Install CodeIgniter on the Ubuntu system.
Now download the CodeIgniter from the official website:
cd /var/www/htmlwget https://github.com/bcit-ci/CodeIgniter/archive/refs/tags/3.1.11.zip
Extract the archive file and place it in the document root:
unzip 3.1.11.zip mv CodeIgniter-3.1.11/ codeigniter
Step 3. Create a Database CodeIgniter.
CodeIgniter uses the MySQL database to store all its data. Log in to your MySQL server with the following command and enter your MySQL root password:
mysql -u root -p
Once you’re in the MySQL console, create a new database:
CREATE DATABASE codeigniterdb; GRANT ALL PRIVILEGES ON codeigniterdb.* TO 'codeigniter_user'@'localhost' IDENTIFIED BY 'your-passwd'; FLUSH PRIVILEGES; EXIT;
Step 4. Configure CodeIgniter.
Once successfully creating the database, edit the database configuration file and update the database setting:
nano /var/www/html/codeigniter/config/database.php
Add the following lines:
$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'codeigniter_user', 'password' => 'your-passwd', 'database' => 'codeigniterdb', '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 );
Next, configure the base URL for your application:
nano /var/www/html/codeigniter/config/config.php
Update base_url with your domain name:
$config['base_url'] = 'http://codeigniter.linuxtips.us';
Step 5. Configure Apache.
Now create an apache virtual host for your CodeIgniter:
nano /etc/apache2/sites-available/codeigniter.conf
Add the following file:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/codeigniter ServerName codeigniter.linuxtips.us ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory "/var/www/html/codeigniter"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost>
Restart apache2 service:
sudo a2ensite codeigniter.conf sudo systemctl restart apache2
Step 6. Accessing CodeIgniter.
Now you can access the CodeIgniter application in your browser and start developing from CodeIgniter:
http://codeigniter.linuxtips.us
That’s all you need to do to install CodeIgniter on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on CodeIgniter PHP Framework, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.