How To Install CodeIgniter on Debian 13

CodeIgniter is a powerful, lightweight PHP framework designed for developers who need a simple yet elegant toolkit to create full-featured web applications. This open-source framework follows the Model-View-Controller (MVC) architectural pattern, making it an excellent choice for building dynamic websites with clean, maintainable code. With its small footprint, rich set of libraries, and exceptional performance, CodeIgniter has become a preferred framework for rapid web development.
Debian 13 “Trixie” provides an ideal environment for hosting CodeIgniter applications. The latest Debian release includes PHP 8.4 by default, offering enhanced performance and modern language features that complement CodeIgniter 4’s capabilities. Whether you’re building a personal blog, enterprise application, or RESTful API, this comprehensive guide will walk you through every step of installing CodeIgniter 4 on Debian 13.
This tutorial covers both Composer-based installation and manual setup methods, ensuring you can choose the approach that best fits your workflow. By the end of this guide, you’ll have a fully functional CodeIgniter installation ready for development.
Prerequisites
Before beginning the installation process, ensure your system meets the following requirements. CodeIgniter 4 requires PHP 7.4 or newer, though PHP 8.1 or later is recommended for optimal performance and security. Debian 13 ships with PHP 8.4, which exceeds these requirements and provides excellent compatibility.
You’ll need a Debian 13 system with root or sudo privileges to execute administrative commands. A database server is essential for most web applications—this guide uses MariaDB, though MySQL works equally well. For the web server component, Apache will serve as the primary choice, though Nginx is a viable alternative.
Several PHP extensions are mandatory for CodeIgniter functionality. These include php-cli for command-line operations, php-mysql for database connectivity, php-zip for archive handling, php-gd for image manipulation, php-mbstring for multibyte string processing, php-curl for HTTP requests, php-xml for XML parsing, php-pear for package management, php-bcmath for arbitrary precision mathematics, and php-intl for internationalization support.
If you plan to use the Composer installation method, you’ll need Composer 2.0.14 or later. Basic command-line knowledge will help you navigate the installation smoothly. Finally, have a domain name ready or prepare to use localhost for testing purposes.
Step 1: Update System Packages
Maintaining an updated system is crucial for security and compatibility. Begin by refreshing your package repository information to ensure you’re installing the latest available versions. Open your terminal and execute:
sudo apt update
This command synchronizes your package index with Debian’s repositories. Next, upgrade all existing packages to their newest versions:
sudo apt upgrade -y
The -y flag automatically confirms the upgrade process. Now install essential utilities that you’ll need throughout the installation:
sudo apt install curl wget unzip git -y
These tools enable you to download files, extract archives, and manage version control. Curl and wget facilitate file downloads from remote servers, unzip handles compressed archives, and git provides version control capabilities. Your system is now prepared for CodeIgniter installation.
Step 2: Install Apache Web Server
Apache remains one of the most reliable web servers for PHP applications, offering robust performance and extensive module support. Install Apache along with the PHP Apache module:
sudo apt install apache2 libapache2-mod-php -y
Once installation completes, start the Apache service and configure it to launch automatically at system boot:
sudo systemctl start apache2
sudo systemctl enable apache2
Verify Apache is running correctly by opening your web browser and navigating to http://localhost or your server’s IP address. You should see the Apache default welcome page, confirming successful installation.
CodeIgniter requires URL rewriting for clean URLs and proper routing. Enable Apache’s rewrite module:
sudo a2enmod rewrite
Restart Apache to apply the module changes:
sudo systemctl restart apache2
Apache is now configured and ready to serve your CodeIgniter application.
Step 3: Install PHP and Required Extensions
Debian 13 includes PHP 8.4 in its default repositories, providing cutting-edge features and performance improvements. Install PHP alongside all required extensions in a single command:
sudo apt install php php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-intl -y
Each extension serves specific purposes within CodeIgniter. The php-mysql extension enables database connectivity to MariaDB or MySQL servers. The php-mbstring extension handles multibyte string operations, essential for international character support. The php-intl extension provides internationalization features for building multilingual applications.
The php-curl extension facilitates HTTP requests to external APIs and services. The php-xml extension processes XML data structures. Additional extensions like php-gd handle image manipulation, php-zip manages compressed files, and php-bcmath performs arbitrary precision calculations.
Confirm your PHP installation by checking the version:
php -v
You should see PHP 8.4 displayed. List all installed PHP modules to verify the extensions:
php -m
Your PHP environment is now fully configured for CodeIgniter development.
Step 4: Install and Configure MariaDB Database
Most dynamic web applications require database functionality. Install the MariaDB server package:
sudo apt install mariadb-server -y
Start the MariaDB service and enable automatic startup at boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure your MariaDB installation by running the security script:
sudo mysql_secure_installation
This interactive script helps you set a root password, remove anonymous users, disable remote root login, and delete test databases. Follow the prompts to enhance database security.
Access the MariaDB shell to create a dedicated database for your CodeIgniter project:
sudo mysql -u root -p
Enter your root password when prompted. Create a new database:
CREATE DATABASE codeigniterdb;
Create a dedicated user with a strong password:
CREATE USER 'codeigniter'@'localhost' IDENTIFIED BY 'your_secure_password';
Replace your_secure_password with a complex password combining letters, numbers, and special characters. Grant the user full privileges on the CodeIgniter database:
GRANT ALL ON codeigniterdb.* to 'codeigniter'@'localhost';
Flush privileges to ensure changes take effect immediately:
FLUSH PRIVILEGES;
Exit the MariaDB shell:
EXIT;
Your database environment is ready for CodeIgniter integration.
Step 5: Install Composer
Composer is PHP’s dependency management tool, recommended for installing and maintaining CodeIgniter 4 projects. Download the Composer installer script:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Execute the installer:
php composer-setup.php
Remove the installer file to keep your system clean:
php -r "unlink('composer-setup.php');"
Move Composer to a system-wide location for global access:
sudo mv composer.phar /usr/local/bin/composer
Verify the installation and check the Composer version:
composer --version
Ensure you have Composer 2.0.14 or later. Composer is now ready to manage your CodeIgniter installation.
Step 6: Install CodeIgniter 4 Using Composer
The Composer method provides the most streamlined CodeIgniter installation experience. Navigate to your web server’s document root:
cd /var/www/
Create a new CodeIgniter project using the App Starter template:
composer create-project codeigniter4/appstarter codeigniter
Composer downloads CodeIgniter 4 and all its dependencies automatically. The App Starter package includes the framework code, application structure, and necessary configuration files. This process may take several minutes depending on your internet connection speed.
Once complete, you’ll have a complete project structure with app, public, and writable directories. The app folder contains your application code, public holds web-accessible files, and writable stores logs and cache files.
Set appropriate ownership for web server access:
sudo chown -R www-data:www-data /var/www/codeigniter
Configure proper permissions:
sudo chmod -R 755 /var/www/codeigniter
These permissions ensure Apache can read application files while maintaining security.
Step 7: Install CodeIgniter 4 Manually
If you prefer manual installation or don’t want to use Composer, you can download CodeIgniter directly from GitHub. This method works well for environments without Composer access or when you want complete control over the installation.
Fetch the latest CodeIgniter release version automatically:
LATEST_VER=$(curl -s https://api.github.com/repos/codeigniter4/CodeIgniter4/releases/latest|grep tag_name | cut -d '"' -f 4)
Download the release archive:
wget https://github.com/codeigniter4/CodeIgniter4/archive/refs/tags/${LATEST_VER}.tar.gz -O CodeIgniter-${LATEST_VER}.tar.gz
Extract the downloaded archive and remove the compressed file:
tar xvf CodeIgniter-${LATEST_VER}.tar.gz && rm -f CodeIgniter-${LATEST_VER}.tar.gz
Move the extracted directory to your web server location:
sudo mv CodeIgniter4-*/ /var/www/codeigniter
Apply the same ownership and permissions as the Composer method:
sudo chown -R www-data:www-data /var/www/codeigniter
sudo chmod -R 755 /var/www/codeigniter
Your manual installation is complete and ready for configuration.
Step 8: Configure CodeIgniter Environment
Proper configuration ensures your CodeIgniter application connects to the database and operates in the correct mode. Navigate to the CodeIgniter directory:
cd /var/www/codeigniter
Copy the example environment file to create your configuration:
cp env .env
Open the environment file with your preferred text editor:
sudo nano .env
Set the environment mode to development for testing and debugging:
CI_ENVIRONMENT = development
Development mode displays detailed error messages, helping you identify and fix issues quickly. Configure your database connection parameters:
database.default.hostname = localhost
database.default.database = codeigniterdb
database.default.username = codeigniter
database.default.password = your_secure_password
database.default.DBDriver = MySQLi
Replace your_secure_password with the password you created earlier. Set your application’s base URL:
app.baseURL = 'http://your-domain.com'
For local testing, use http://localhost or your server’s IP address. Generate an encryption key for security features. CodeIgniter uses this key for session encryption and data protection.
Save the file and exit your text editor. Your CodeIgniter installation is now configured with proper database credentials and environment settings.
Step 9: Configure Apache Virtual Host
Virtual host configuration directs Apache to serve your CodeIgniter application correctly. Create a new virtual host configuration file:
sudo nano /etc/apache2/sites-available/codeigniter.conf
Add the following configuration, adjusting ServerName to match your domain:
<VirtualHost *:80>
ServerName codeigniter.example.com
DocumentRoot /var/www/codeigniter/public
<Directory /var/www/codeigniter>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/codeigniter-error.log
CustomLog ${APACHE_LOG_DIR}/codeigniter-access.log combined
</VirtualHost>
The DocumentRoot directive points to the public folder, ensuring only web-accessible files are served. The AllowOverride All setting enables .htaccess files for URL rewriting, which CodeIgniter requires for clean URLs.
Enable your new virtual host configuration:
sudo a2ensite codeigniter.conf
Disable the default site if you’re dedicating this server to CodeIgniter:
sudo a2dissite 000-default.conf
Test your Apache configuration for syntax errors:
sudo apache2ctl configtest
If the test returns “Syntax OK,” reload Apache to apply changes:
sudo systemctl reload apache2
For local testing with a custom domain, edit your hosts file:
sudo nano /etc/hosts
Add an entry mapping your domain to localhost:
127.0.0.1 codeigniter.example.com
Your virtual host configuration is complete.
Step 10: Test CodeIgniter Installation
Open your web browser and navigate to your configured domain or localhost address. You should see the CodeIgniter welcome page displaying “Welcome to CodeIgniter 4!” This confirms successful installation.
The welcome page indicates that URL routing works correctly and Apache serves files from the proper directory. Check that the environment displays correctly—in development mode, you’ll see detailed system information and debugging tools.
Test your database connection by creating a simple controller. Navigate to app/Controllers and create a test file to verify database connectivity. Ensure the writable directory has proper permissions by checking for log files in writable/logs.
Verify URL routing functions properly by accessing different routes. If you encounter 404 errors, review your virtual host configuration and ensure the rewrite module is enabled.
Security Best Practices
Security should be your top priority when deploying CodeIgniter applications. Keep your CodeIgniter installation updated to the latest version, as updates often include critical security patches.
Enable CSRF (Cross-Site Request Forgery) protection in your configuration files. This prevents malicious websites from executing unauthorized commands through authenticated users. CodeIgniter’s query builder automatically uses prepared statements, protecting against SQL injection attacks.
Always validate and sanitize user inputs using CodeIgniter’s validation library. Enable XSS (Cross-Site Scripting) filtering to prevent malicious scripts from executing in user browsers.
Implement secure session management and authentication practices. Use HTTPS with SSL certificates in production environments to encrypt data transmission. Keep your .env file secure and never commit it to version control systems.
Set restrictive file permissions in production—never use 777 permissions, which grant full access to all users. Disable PHP error display in production by setting CI_ENVIRONMENT to production. Conduct regular security audits and maintain backups of your application and database.
Troubleshooting Common Issues
404 Page Not Found errors often indicate routing or virtual host configuration problems. Verify that Apache’s rewrite module is enabled using sudo a2enmod rewrite. Check that your virtual host DocumentRoot points to the public folder, not the main CodeIgniter directory.
Review route definitions in app/Config/Routes.php to ensure they match your URL structure. Remember that Linux file systems are case-sensitive, so controller and method names must match exactly.
Database connection failures typically stem from incorrect credentials in the .env file. Verify your database name, username, and password match what you configured in MariaDB. Ensure the MariaDB service is running using sudo systemctl status mariadb.
Permission errors occur when Apache cannot read or write necessary files. Ensure www-data owns all CodeIgniter files and directories. The writable directory needs write permissions for logs and cache files.
White screens or 500 Internal Server errors require detailed error information. Enable development mode by setting CI_ENVIRONMENT = development in your .env file. Check Apache error logs for detailed information:
sudo tail -f /var/log/apache2/error.log
If using Composer and experiencing dependency issues, try updating packages:
composer update
Clear Composer’s cache if problems persist:
composer clear-cache
Congratulations! You have successfully installed CodeIgniter. Thanks for using this tutorial for installing the latest version of CodeIgniter on Debian 13 “Trixie” system. For additional help or useful information, we recommend you check the official CodeIgniter website.