How To Install CodeIgniter on Linux Mint 22
Installing CodeIgniter on Linux Mint 22 opens the door to rapid PHP web development with one of the most popular and lightweight frameworks available today. This comprehensive guide walks you through every step of the installation process, from system preparation to running your first CodeIgniter application.
CodeIgniter stands out as an exceptional PHP framework due to its minimal footprint, clear documentation, and gentle learning curve. The framework follows the Model-View-Controller (MVC) architectural pattern, which promotes organized code structure and maintainability. With its small download size of less than 3MB and straightforward configuration, CodeIgniter enables developers to build robust web applications quickly without the complexity often associated with other frameworks.
Linux Mint 22, based on Ubuntu’s long-term support release, provides an ideal environment for web development. Its stability, user-friendly interface, and excellent package management system make it perfect for both beginners and experienced developers. The operating system comes with essential development tools pre-installed and offers seamless compatibility with PHP frameworks like CodeIgniter.
This tutorial targets developers ranging from beginners to intermediate levels who want to set up a professional CodeIgniter development environment. By following these instructions, you’ll have a fully functional CodeIgniter installation ready for building dynamic web applications within 30-45 minutes.
System Requirements and Prerequisites
PHP Environment Setup
CodeIgniter 4 requires PHP 7.2 or newer, though PHP 8.1+ is strongly recommended for optimal performance and security. The framework demands several PHP extensions for full functionality:
Essential PHP Extensions:
- intl: Provides internationalization support for multi-language applications
- mbstring: Handles multibyte string operations for Unicode compatibility
- json: Processes JSON data structures used throughout modern web development
- mysqlnd or mysqli: Enables database connectivity with MySQL/MariaDB
Recommended PHP Extensions:
- curl: Facilitates HTTP client functionality for external API integrations
- xml: Processes XML documents and enables SOAP web services
- zip: Handles archive operations for file compression and extraction
- gd or ImageMagick: Provides image manipulation capabilities for dynamic graphics
Web Server Configuration
Apache HTTP Server 2.4+ serves as the primary web server choice due to its robust feature set and extensive documentation. The server requires mod_rewrite enabled for clean URL functionality. Alternative options include Nginx for high-performance scenarios, LiteSpeed for commercial applications, or PHP’s built-in development server for local testing.
Key Apache requirements include virtual host support for multiple projects and .htaccess file processing for URL rewriting rules. These features enable CodeIgniter’s routing system to function correctly and provide the clean URLs that modern web applications demand.
Database Server Requirements
CodeIgniter supports multiple database systems including MySQL 5.1+, MariaDB, PostgreSQL, SQLite, and Microsoft SQL Server. For Linux Mint 22 installations, MySQL 8.0+ or MariaDB 10.4+ offer the best compatibility and performance. The chosen database system must have appropriate PDO drivers installed to ensure seamless connectivity.
System Prerequisites Checklist
Before beginning the installation process, verify these system requirements:
- Operating System: Linux Mint 22 with recent updates installed
- User Privileges: Root access or sudo privileges for software installation
- Internet Connection: Active connection for downloading packages and dependencies
- Disk Space: Minimum 500MB free space for complete installation with room for development
- Memory: At least 1GB RAM for comfortable development environment performance
Preparing the Linux Mint 22 Environment
System Updates and Package Management
Start by updating your Linux Mint 22 system to ensure all packages are current and security patches are applied:
sudo apt update
sudo apt upgrade -y
The first command refreshes the package repository information, while the second upgrades all installed packages to their latest versions. Install essential build tools and utilities needed for web development:
sudo apt install curl wget unzip git software-properties-common
These tools provide file downloading capabilities, archive extraction, version control, and repository management functions essential for modern PHP development workflows.
Apache Web Server Installation and Configuration
Install Apache HTTP Server using the package manager:
sudo apt install apache2
Configure Apache service management to ensure automatic startup:
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
The status command should display “active (running)” indicating successful installation. Configure the firewall to allow HTTP and HTTPS traffic:
sudo ufw allow 'Apache Full'
Test the Apache installation by opening a web browser and navigating to http://localhost
. You should see the Apache2 Ubuntu Default Page confirming successful installation.
Key Apache directories to remember:
- Document root:
/var/www/html/
- Configuration files:
/etc/apache2/
- Available sites:
/etc/apache2/sites-available/
- Enabled sites:
/etc/apache2/sites-enabled/
- Log files:
/var/log/apache2/
PHP Installation and Essential Extensions
Install PHP along with the Apache module and essential extensions:
sudo apt install php libapache2-mod-php php-cli php-common php-mbstring php-xml php-zip php-curl php-mysql php-intl php-json php-gd
This comprehensive installation includes all necessary components for CodeIgniter development. Verify the PHP installation and version:
php -v
Edit the PHP configuration file to optimize settings for web development:
sudo nano /etc/php/8.3/apache2/php.ini
Critical PHP configuration adjustments:
memory_limit = 256M
– Increases available memory for PHP processesupload_max_filesize = 64M
– Allows larger file uploadspost_max_size = 64M
– Increases POST request size limitsmax_execution_time = 300
– Extends script execution time for development
After making changes, restart Apache to apply the new configuration:
sudo systemctl restart apache2
Database Server Setup and Security
Install MariaDB server, which offers better performance and compatibility with Linux Mint:
sudo apt install mariadb-server mariadb-client
Alternatively, install MySQL if preferred:
sudo apt install mysql-server mysql-client
Start and enable the database service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Run the security installation script to configure initial database security:
sudo mysql_secure_installation
This interactive script prompts for several security configurations:
- Set root password (create a strong password)
- Remove anonymous users (recommended: Yes)
- Disallow root login remotely (recommended: Yes)
- Remove test database (recommended: Yes)
- Reload privilege tables (recommended: Yes)
Apache Module Configuration
Enable essential Apache modules for CodeIgniter functionality:
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
The rewrite module enables clean URLs, SSL provides HTTPS support, and headers allows custom HTTP header manipulation. Restart Apache to activate these modules:
sudo systemctl restart apache2
Verify enabled modules:
apache2ctl -M | grep -E "(rewrite|ssl|headers)"
Installing Composer for Dependency Management
Understanding Composer’s Role
Composer serves as PHP’s de facto dependency manager, revolutionizing how developers handle third-party packages and autoloading. For CodeIgniter installations, Composer manages framework updates, installs additional packages, and provides PSR-4 autoloading capabilities that modern PHP development demands.
Composer Installation Process
Download and install Composer using the official installer script:
curl -sS https://getcomposer.org/installer | php
This command downloads the Composer installer and executes it using PHP. Move the generated composer.phar file to a global location:
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
Verify the installation:
composer --version
The output should display Composer version information, confirming successful installation.
Alternative Installation Method
Linux Mint users can alternatively install Composer through the package manager:
sudo apt install composer
However, this method may provide an older version. The manual installation ensures you have the latest Composer release with all current features and security updates.
Composer Configuration and Optimization
Configure Composer for optimal performance:
composer config --global process-timeout 2000
composer config --global cache-ttl 86400
These settings increase the process timeout for large installations and optimize cache behavior for better performance during subsequent package installations.
Installing CodeIgniter Using Composer
Project Directory Preparation
Navigate to the web server’s document root:
cd /var/www/html
For development purposes, you might prefer installing in your home directory:
cd ~/development
mkdir codeigniter-projects
cd codeigniter-projects
CodeIgniter Installation Command
Create a new CodeIgniter project using Composer’s create-project command:
composer create-project codeigniter4/appstarter my-codeigniter-app
Replace “my-codeigniter-app” with your preferred project name. This command downloads CodeIgniter 4 and all dependencies, creating a complete project structure ready for development.
For specific version installation:
composer create-project codeigniter4/appstarter:4.3.* my-codeigniter-app
The installation process typically takes 2-5 minutes depending on internet connection speed and system performance.
Project Structure Analysis
After installation, examine the created directory structure:
my-codeigniter-app/
├── app/ # Application logic (controllers, models, views)
├── public/ # Web-accessible directory (document root)
├── system/ # CodeIgniter core files
├── vendor/ # Composer dependencies
├── writable/ # Cache, logs, uploads
├── .env # Environment configuration
├── composer.json # Dependency configuration
└── spark # CLI tool
Key directories explained:
app/
: Contains your application code including controllers, models, views, and configurationpublic/
: Serves as the web server document root containing index.php and assetssystem/
: Houses CodeIgniter core framework files (rarely modified)vendor/
: Stores Composer-managed dependencies and autoloaderwritable/
: Provides storage for cache files, logs, and file uploads
File Permissions Configuration
Set appropriate file permissions for web server access:
cd my-codeigniter-app
sudo chown -R www-data:www-data .
sudo chmod -R 755 .
sudo chmod -R 777 writable/
For development environments, more permissive settings work better:
chmod -R 755 .
chmod -R 777 writable/
chmod -R 777 public/uploads/ # If you plan to handle file uploads
Environment Configuration Setup
Copy the environment template and configure it:
cp env .env
nano .env
Essential environment settings:
CI_ENVIRONMENT = development
app.baseURL = 'http://localhost/my-codeigniter-app/public/'
database.default.hostname = localhost
database.default.database = codeigniter_db
database.default.username = ci_user
database.default.password = your_secure_password
The environment file keeps sensitive configuration data separate from your codebase, enabling different settings for development, testing, and production environments.
Configuring Apache Virtual Host for CodeIgniter
Creating Virtual Host Configuration
Create a new Apache virtual host configuration file:
sudo nano /etc/apache2/sites-available/codeigniter.conf
Add the following virtual host configuration:
<VirtualHost *:80>
ServerName codeigniter.local
ServerAlias www.codeigniter.local
DocumentRoot /var/www/html/my-codeigniter-app/public
<Directory /var/www/html/my-codeigniter-app/public>
AllowOverride All
Require all granted
DirectoryIndex index.php
</Directory>
<Directory /var/www/html/my-codeigniter-app>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/codeigniter_error.log
CustomLog ${APACHE_LOG_DIR}/codeigniter_access.log combined
</VirtualHost>
Configuration breakdown:
- ServerName: Sets the primary domain name for the virtual host
- DocumentRoot: Points to CodeIgniter’s public directory (crucial for security)
- AllowOverride All: Enables .htaccess file processing for URL rewriting
- DirectoryIndex: Specifies index.php as the default file
- Error/Access logs: Separate log files for easier debugging
Activating the Virtual Host
Enable the new site configuration:
sudo a2ensite codeigniter.conf
Optionally disable the default Apache site to avoid conflicts:
sudo a2dissite 000-default.conf
Test the Apache configuration for syntax errors:
sudo apache2ctl configtest
If the test returns “Syntax OK,” reload Apache to apply changes:
sudo systemctl reload apache2
Local Domain Configuration
Add the local domain to your hosts file:
sudo nano /etc/hosts
Add this line:
127.0.0.1 codeigniter.local www.codeigniter.local
This configuration allows you to access your CodeIgniter application using a friendly domain name instead of localhost paths.
SSL Configuration for Development (Optional)
For HTTPS development, create a self-signed certificate:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/codeigniter.key \
-out /etc/ssl/certs/codeigniter.crt
Create an SSL virtual host configuration:
<VirtualHost *:443>
ServerName codeigniter.local
DocumentRoot /var/www/html/my-codeigniter-app/public
SSLEngine on
SSLCertificateFile /etc/ssl/certs/codeigniter.crt
SSLCertificateKeyFile /etc/ssl/private/codeigniter.key
<Directory /var/www/html/my-codeigniter-app/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Database Setup and Configuration
Creating the Database
Access the MariaDB/MySQL console:
sudo mysql -u root -p
Create a new database for your CodeIgniter application:
CREATE DATABASE codeigniter_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
The UTF8MB4 character set provides full Unicode support including emoji and special characters commonly used in modern web applications.
Database User Management
Create a dedicated database user for enhanced security:
CREATE USER 'ci_user'@'localhost' IDENTIFIED BY 'your_secure_password_here';
GRANT ALL PRIVILEGES ON codeigniter_db.* TO 'ci_user'@'localhost';
FLUSH PRIVILEGES;
Test the new user connection:
mysql -u ci_user -p codeigniter_db
CodeIgniter Database Configuration
Update the database configuration in your .env file:
database.default.hostname = localhost
database.default.database = codeigniter_db
database.default.username = ci_user
database.default.password = your_secure_password_here
database.default.DBDriver = MySQLi
database.default.DBPrefix =
database.default.port = 3306
For production environments, consider using environment-specific configuration files to keep sensitive data secure.
Testing Database Connectivity
Create a simple test to verify database connectivity. Add this temporary route to app/Config/Routes.php
:
$routes->get('/dbtest', function() {
$db = \Config\Database::connect();
if ($db->connID) {
return "Database connection successful!";
} else {
return "Database connection failed!";
}
});
Running and Testing Your CodeIgniter Application
Using the Built-in Development Server
CodeIgniter includes a built-in development server perfect for local testing:
cd /var/www/html/my-codeigniter-app
php spark serve
Access your application at http://localhost:8080
. For custom port assignment:
php spark serve --port=8081 --host=0.0.0.0
The --host=0.0.0.0
option allows network access, useful for testing on multiple devices.
Apache Virtual Host Testing
If you configured a virtual host, access your application using:
http://codeigniter.local
You should see the CodeIgniter welcome page displaying version information and environment status.
Verification Checklist
Confirm these elements work correctly:
- Welcome page loads: Displays CodeIgniter 4 branding and version
- Clean URLs function: Routes work without index.php in the URL
- Database connectivity: No database-related errors in logs
- File permissions: Writable directories accept new files
- Error reporting: Detailed errors appear in development mode
Creating Your First Controller
Generate a test controller to verify functionality:
php spark make:controller TestController
Edit app/Controllers/TestController.php
:
<?php
namespace App\Controllers;
class TestController extends BaseController
{
public function index()
{
return view('test_view', ['message' => 'CodeIgniter is working perfectly!']);
}
}
Create the corresponding view at app/Views/test_view.php
:
<!DOCTYPE html>
<html>
<head>
<title>CodeIgniter Test</title>
</head>
<body>
<h1><?= $message ?></h1>
<p>Your CodeIgniter installation is successful!</p>
</body>
</html>
Add a route in app/Config/Routes.php
:
$routes->get('/test', 'TestController::index');
Visit http://codeigniter.local/test
to see your custom page.
Troubleshooting Common Installation Issues
Apache Configuration Problems
500 Internal Server Error Solutions:
- Check .htaccess file: Ensure the public/.htaccess file exists and contains proper rewrite rules
- Verify mod_rewrite: Confirm the module is enabled with
apache2ctl -M | grep rewrite
- File permissions: Verify correct ownership and permissions on all directories
- Apache error logs: Check
/var/log/apache2/error.log
for specific error messages
Database Connection Issues
Common database problems and solutions:
- Authentication failures: Verify username and password in .env file
- Service status: Ensure MariaDB/MySQL is running with
systemctl status mariadb
- Port conflicts: Check if the database is listening on the correct port (3306)
- Host restrictions: Verify the database user has proper host permissions
PHP Extension Problems
Missing extension errors:
# Check installed PHP extensions
php -m
# Install missing extensions
sudo apt install php-extension-name
# Restart Apache after installation
sudo systemctl restart apache2
Composer and Memory Issues
Composer memory exhaustion solutions:
# Temporarily increase PHP memory limit
php -d memory_limit=512M /usr/local/bin/composer install
# Permanent solution in php.ini
memory_limit = 512M
File Permission Troubleshooting
Systematic permission fixing:
# Reset all permissions
sudo chown -R www-data:www-data /var/www/html/my-codeigniter-app
find /var/www/html/my-codeigniter-app -type d -exec chmod 755 {} \;
find /var/www/html/my-codeigniter-app -type f -exec chmod 644 {} \;
chmod -R 777 /var/www/html/my-codeigniter-app/writable
Best Practices and Security Recommendations
Production Security Measures
Essential security configurations:
- Environment mode: Change
CI_ENVIRONMENT
toproduction
in .env - Debug mode: Disable detailed error reporting for public applications
- File permissions: Use restrictive permissions (755 for directories, 644 for files)
- Database security: Use strong passwords and limited user privileges
- HTTPS implementation: Install and configure SSL certificates for encrypted connections
Performance Optimization Strategies
OPcache configuration in /etc/php/8.1/apache2/php.ini
:
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
CodeIgniter caching configuration in app/Config/Cache.php
:
public string $handler = 'file'; // or 'redis', 'memcached'
public int $ttl = 60;
public string $prefix = 'myapp_';
Development Workflow Enhancements
Useful Spark commands for development:
# Generate models, controllers, migrations
php spark make:model UserModel
php spark make:controller UserController
php spark make:migration CreateUsersTable
# Database operations
php spark migrate
php spark db:seed UserSeeder
# Clear application cache
php spark cache:clear
Backup and Version Control
Git repository initialization:
cd /var/www/html/my-codeigniter-app
git init
git add .
git commit -m "Initial CodeIgniter installation"
Database backup script:
#!/bin/bash
mysqldump -u ci_user -p codeigniter_db > backup_$(date +%Y%m%d_%H%M%S).sql
Congratulations! You have successfully installed CodeIgniter. Thanks for using this tutorial to install the latest version of CodeIgniter PHP framework on the Linux Mint 22 system. For additional help or useful information, we recommend you check the official CodeIgniter website.