DebianDebian Based

How To Install CodeIgniter on Debian 12

Install CodeIgniter on Debian 12

In this tutorial, we will show you how to install CodeIgniter on Debian 12. CodeIgniter, a powerful PHP framework, is the go-to choice for developers seeking to build feature-rich and dynamic web applications.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the CodeIgniter on a Debian 12 (Bookworm).


  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for CodeIgniter.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install CodeIgniter on Debian 12 Bookworm

Step 1. Before installing CodeIgniter, you need to make sure that your Debian 12 system is up-to-date and has the necessary packages installed. You can do this by running the following commands:

sudo apt update

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Set Up LAMP Stack.

Follow these steps to install and configure Apache, MySQL, and PHP:

  • Install Apache:
sudo apt install apache2
  • Install MySQL:
sudo apt install mysql-server
  • Install PHP:
sudo apt-get install php libapache2-mod-php php-mysql

Step 3. Installing Composer.

Composer is a powerful tool that manages PHP dependencies and aids in CodeIgniter’s smooth functioning. Let’s get it up and running:

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

To verify the successful installation, run:

composer --version

Step 4. Downloading CodeIgniter:

Now that we have Composer installed, let’s proceed with downloading the latest version of CodeIgniter:

cd /var/www/html
mkdir my_codeigniter_project
cd my_codeigniter_project
composer create-project codeigniter4/appstarter .

Step 5. Configuring Apache.

To serve CodeIgniter from your Debian system, you need to configure Apache and set up a virtual host:

sudo nano /etc/apache2/sites-available/my_codeigniter_project.conf

Add the following configuration (replace ‘my_codeigniter_project‘ with your project name and directory):

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/my_codeigniter_project/public

<Directory /var/www/html/my_codeigniter_project/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Enable the Virtual Host:

sudo a2ensite my_codeigniter_project.conf
sudo a2enmod rewrite

Restart the Apache webserver so that the changes take place:

sudo systemctl restart apache2

Step 6. Database Setup:

Next, we’ll set up a MySQL database to work seamlessly with CodeIgniter:

mysql -u root -p

Create a New Database and User:

CREATE DATABASE my_codeigniter_db;
CREATE USER 'ci_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON my_codeigniter_db.* TO 'ci_user'@'localhost';

Step 7. CodeIgniter Configuration:

Let’s configure CodeIgniter to ensure it communicates effectively with Apache and your MySQL database:

nano /var/www/html/my_codeigniter_project/app/config/App.php

Locate and modify the $baseURL variable to match your virtual host configuration:

public $baseURL = 'http://your_domain_or_ip/';

Configure the Database:

nano /var/www/html/my_codeigniter_project/app/config/Database.php

Update the $default array with your database details:

public $default = [
    'DSN'      => '',
    'hostname' => 'localhost',
    'username' => 'ci_user',
    'password' => 'your_strong_password',
    'database' => 'my_codeigniter_db',
    'DBDriver' => 'MySQLi',
    'DBPrefix' => '',
    'pConnect' => false,
    'DBDebug'  => (ENVIRONMENT !== 'production'),
    'cacheOn'  => false,
    'cacheDir' => '',
    'charset'  => 'utf8',
    'DBCollat' => 'utf8_general_ci',
    'swapPre'  => '',
    'encrypt'  => false,
    'compress' => false,
    'strictOn' => false,
    'failover' => [],
    'port'     => 3306,

Step 8. Test the Installation.

With the configuration in place, it’s time to ensure CodeIgniter is working correctly:

nano /var/www/html/my_codeigniter_project/app/Controllers/Test.php

Add a simple controller code:


namespace App\Controllers;

class Test extends BaseController
    public function index()
        echo 'CodeIgniter installation successful!';

Access the Controller via a Web Browser:

Now we visit http://your_domain_or_ip/test to see the message displayed.

Step 9. Common Troubleshooting.

During the installation process, you may encounter some common issues and errors. Here are a few troubleshooting tips:

  • Mod_Rewrite Not Enabled.

Ensure that mod_rewrite is enabled on Apache to support clean URLs. Use the following command to enable it:

sudo a2enmod rewrite
sudo systemctl restart apache2
  • Permissions Issues:

Make sure the necessary folders have proper permissions. Use the following command to grant necessary access:

sudo chown -R www-data:www-data /var/www/html/my_codeigniter_project
sudo chmod -R 755 /var/www/html/my_codeigniter_project
  • Database Connection Error.

Double-check the database configuration in Database.php and ensure the correct username, password, and database name are provided.

Congratulations! You have successfully installed CodeIgniter. Thanks for using this tutorial for installing the latest version of CodeIgniter on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official CodeIgniter website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!


r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button