How To Install CodeIgniter on Fedora 42
Installing CodeIgniter on Fedora 42 offers developers a powerful combination of a robust PHP framework with a cutting-edge Linux distribution. CodeIgniter stands out among PHP frameworks for its lightweight footprint, impressive performance, and straightforward implementation of the Model-View-Controller (MVC) architecture. This guide walks you through the complete installation process, from preparing your Fedora 42 environment to optimizing your CodeIgniter setup for development.
Introduction
CodeIgniter represents one of the most efficient PHP frameworks available today. Its small footprint and minimal configuration requirements make it an excellent choice for developers looking to build dynamic web applications quickly. The framework provides a rich set of libraries for common tasks while maintaining exceptional performance compared to other frameworks.
Fedora 42, the latest release from the Fedora Project, provides a solid foundation for modern web development with its up-to-date packages and security features. The distribution comes with excellent support for PHP development environments, making it an ideal platform for CodeIgniter applications.
In this comprehensive guide, you’ll learn not only how to install CodeIgniter on Fedora 42 but also how to configure your environment for optimal performance and security. By following these steps, you’ll establish a professional development environment ready for building sophisticated web applications.
Prerequisites
Before beginning the CodeIgniter installation process, ensure your system meets the necessary requirements and you have the required background knowledge.
System Requirements
CodeIgniter 4, the latest major version, requires:
- PHP version 7.4 or higher (PHP 8.0+ recommended for best performance)
- MySQL 5.1+ or MariaDB 10.0+ for database functionality
- At least 2GB RAM (4GB recommended for development environment)
- Minimum 20GB free disk space for system, web server, and application files
Fedora 42 typically ships with newer versions of these components, but it’s always good to verify before proceeding.
Required Knowledge
While this guide provides detailed instructions, basic familiarity with these concepts will help:
- Linux command line navigation and basic commands
- Web server concepts and configuration principles
- PHP development fundamentals
- Database management basics
Complete beginners can still follow along, but may need to research some concepts further.
User Privileges
Most installation steps require administrative privileges. You should either:
- Have root access to your Fedora 42 system
- Use a regular user account with sudo privileges
For security reasons, it’s recommended to create a dedicated user with sudo privileges rather than working directly as root. If needed, create a new user with:
# Create new user
sudo useradd -m username
# Set password
sudo passwd username
# Add user to wheel group for sudo access
sudo usermod -aG wheel username
Step 1: Update the System
Always begin with a fully updated system. This ensures compatibility with the latest packages and includes important security patches.
First, update the package repository information:
sudo dnf check-update
Next, upgrade all installed packages to their latest versions:
sudo dnf upgrade -y
The -y
flag automatically confirms the upgrade prompt. This process may take several minutes depending on your system and internet connection speed. After updating, it’s advisable to reboot your system to ensure all updates are properly applied:
sudo systemctl reboot
Once your system restarts, verify the update was successful by checking the Fedora version:
cat /etc/fedora-release
This should confirm you’re running Fedora 42.
Step 2: Install Required Software
CodeIgniter runs on the traditional LAMP stack (Linux, Apache, MySQL, PHP). Let’s install each component.
Apache Web Server Installation
Apache is one of the most popular web servers and works excellently with CodeIgniter applications.
Install Apache with:
sudo dnf install httpd -y
Start the Apache service and enable it to launch automatically at system startup:
sudo systemctl start httpd
sudo systemctl enable httpd
Verify Apache is running correctly:
sudo systemctl status httpd
You should see “active (running)” in the output. Test Apache by opening a web browser and navigating to http://localhost
or http://your-server-ip
. You should see the default Apache test page.
PHP and Extensions Installation
CodeIgniter 4 requires PHP 7.4 or newer. Fedora 42 typically includes PHP 8.1 or newer in its repositories.
Install PHP and necessary extensions:
sudo dnf install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-intl php-sqlite3 -y
This command installs PHP with extensions required by CodeIgniter and most modern web applications.
Verify your PHP installation by checking the version:
php -v
Create a test PHP file to ensure PHP is working with Apache:
sudo echo "" > /var/www/html/info.php
Access this file in your browser at http://localhost/info.php
or http://your-server-ip/info.php
. If you see the PHP information page, PHP is correctly installed and working with Apache.
For security, remember to remove this file after testing:
sudo rm /var/www/html/info.php
MySQL/MariaDB Installation
CodeIgniter supports various databases, but MySQL/MariaDB is the most common choice.
Install MariaDB (MySQL fork):
sudo dnf install mariadb-server -y
Start and enable the MariaDB service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure your MariaDB installation:
sudo mysql_secure_installation
Follow the prompts to:
- Set a root password
- Remove anonymous users
- Disallow root login remotely
- Remove test database
- Reload privilege tables
Create a database for your CodeIgniter application:
sudo mysql -u root -p
Enter your root password, then at the MariaDB prompt:
CREATE DATABASE codeigniter;
CREATE USER 'ciuser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON codeigniter.* TO 'ciuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Remember to replace ‘your_strong_password’ with an actual secure password.
Composer Installation
Composer is the recommended way to install CodeIgniter and manage PHP dependencies.
Install Composer:
sudo dnf install composer -y
Verify the installation:
composer --version
Step 3: Download CodeIgniter
There are two methods to install CodeIgniter: using Composer (recommended) or manual download.
Using Composer Method
The Composer method is preferred as it handles dependencies automatically and simplifies updates.
Navigate to your web directory:
cd /var/www
Create a new CodeIgniter project:
sudo composer create-project codeigniter4/appstarter ci4app
This command creates a new directory called ci4app
with a fresh CodeIgniter installation.
Manual Download Method
If you prefer not to use Composer, download CodeIgniter directly:
cd /var/www
sudo wget https://github.com/codeigniter4/framework/archive/refs/tags/v4.3.5.zip
sudo unzip v4.3.5.zip
sudo mv framework-4.3.5 ci4app
sudo rm v4.3.5.zip
Note: Check the CodeIgniter GitHub repository for the latest version number and adjust the commands accordingly.
File Organization Best Practices
For security and organization:
- Keep the
system
directory outside the web root if possible - Only expose the
public
directory to the web server - Maintain proper separation between application and system files
Ideally, structure your files like this:
/var/www/
├── ci4app/ # CodeIgniter application (not directly web-accessible)
│ ├── app/ # Your application code
│ ├── system/ # CodeIgniter system files
│ ├── public/ # Web-accessible directory (document root)
│ └── ...
Step 4: Configure Apache for CodeIgniter
CodeIgniter uses a front controller pattern where all requests go through index.php
. Apache needs to be configured to handle this correctly.
Creating Virtual Host Configuration
Create a virtual host configuration file:
sudo nano /etc/httpd/conf.d/ci4app.conf
Add the following configuration:
<VirtualHost *:80>
ServerName ci4app.local
# Or use your actual domain: ServerName yourdomain.com
DocumentRoot /var/www/ci4app/public
<Directory /var/www/ci4app/public>
AllowOverride All
Require all granted
Options -Indexes +FollowSymLinks
</Directory>
ErrorLog /var/log/httpd/ci4app-error.log
CustomLog /var/log/httpd/ci4app-access.log combined
</VirtualHost>
This configuration:
- Directs requests for
ci4app.local
to your CodeIgniter installation - Sets the document root to the
public
directory - Allows
.htaccess
to override configurations - Disables directory listing for security
- Creates separate log files for this application
Enable mod_rewrite
CodeIgniter uses Apache’s rewrite module for clean URLs:
sudo dnf install mod_rewrite -y
Fedora typically loads the module automatically after installation.
Configuring .htaccess
Create an .htaccess file in the public directory:
sudo nano /var/www/ci4app/public/.htaccess
Add the following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
This configuration tells Apache to:
- Enable URL rewriting
- Check if the requested URL doesn’t match a file or directory
- Forward the request to index.php, passing the URL segment as an argument
- Provide a fallback for servers without mod_rewrite
Restart Apache
Apply your configuration changes:
sudo systemctl restart httpd
If you encounter errors, check your configuration with:
sudo apachectl configtest
Step 5: Set Permissions
Correct file permissions are crucial for security and functionality. Set proper ownership:
sudo chown -R apache:apache /var/www/ci4app
Set directory permissions:
sudo find /var/www/ci4app -type d -exec chmod 755 {} \;
Set file permissions:
sudo find /var/www/ci4app -type f -exec chmod 644 {} \;
Make writable directories writable:
sudo chmod -R 775 /var/www/ci4app/writable
For enhanced security on production servers, use more restrictive permissions. These settings provide a balance between security and functionality for development environments.
Step 6: Configure CodeIgniter
Now configure CodeIgniter for your environment.
Environment Setup
Create an environment file by copying the template:
cd /var/www/ci4app
sudo cp env .env
Edit the environment file:
sudo nano .env
Set the environment to development:
CI_ENVIRONMENT = development
In production, you would change this to production
, which disables error display and enables other production-specific behaviors.
Base URL Configuration
In the same .env
file, set your base URL:
app.baseURL = 'http://ci4app.local/'
Replace ci4app.local
with your actual domain or IP address. This URL should match the ServerName in your Apache configuration.
Database Configuration
Configure your database connection in the .env
file:
database.default.hostname = localhost
database.default.database = codeigniter
database.default.username = ciuser
database.default.password = your_strong_password
database.default.DBDriver = MySQLi
Replace your_strong_password
with the password you created earlier.
Other Important Settings
While still editing the .env
file, configure these additional settings:
# Cache settings
cache.handler = file
cache.backupHandler = file
# Session settings
session.driver = 'CodeIgniter\Session\Handlers\FileHandler'
session.cookieName = 'ci_session'
session.expiration = 7200
session.savePath = WRITEPATH . 'session'
# Security settings
security.csrfProtection = 'cookie'
security.tokenRandomize = true
Save and close the file.
Step 7: Configure Firewall
Fedora uses firewalld as its default firewall. Configure it to allow web traffic:
# Allow HTTP traffic
sudo firewall-cmd --permanent --add-service=http
# Allow HTTPS traffic (for future use)
sudo firewall-cmd --permanent --add-service=https
# Reload firewall settings
sudo firewall-cmd --reload
Verify the settings:
sudo firewall-cmd --list-services
You should see http
and https
among the allowed services.
For development environments, you might be tempted to disable the firewall entirely, but it’s better to configure it properly as this more closely matches production environments.
Step 8: Testing Your Installation
Now test your CodeIgniter installation.
First, update your host file to recognize your local domain (if using one):
sudo nano /etc/hosts
Add:
127.0.0.1 ci4app.local
Access your site by visiting http://ci4app.local
or http://localhost
in your browser. You should see the CodeIgniter welcome page.
Create a simple test controller to verify functionality:
sudo nano /var/www/ci4app/app/Controllers/Test.php
Add:
<?php
namespace App\Controllers;
class Test extends BaseController
{
public function index()
{
return 'CodeIgniter is working correctly!';
}
}
Access this controller at http://ci4app.local/test
.
Common Troubleshooting
If you encounter a “404 Not Found” error:
- Check Apache error logs:
sudo tail -f /var/log/httpd/ci4app-error.log
- Verify mod_rewrite is enabled:
sudo httpd -M | grep rewrite
- Check .htaccess configuration and file permissions
If you see a database connection error:
- Verify database credentials in
.env
- Confirm MariaDB is running:
sudo systemctl status mariadb
- Test database connection manually:
mysql -u ciuser -p codeigniter
Step 9: Development Environment Setup
Configure your development environment for optimal productivity.
Error Reporting
For development, enable detailed error reporting in .env
:
CI_DEBUG = true
This shows the CodeIgniter debug toolbar and detailed error messages.
Development Tools
Install these useful development tools:
# PHP linting and static analysis
sudo dnf install php-codesniffer -y
# Version control
sudo dnf install git -y
Configure Git for your project:
cd /var/www/ci4app
git init
Create a .gitignore file:
sudo nano .gitignore
Add standard CodeIgniter exclusions:
.env
writable/cache/*
writable/logs/*
writable/session/*
writable/uploads/*
writable/debugbar/*
vendor/
IDE Recommendations
For efficient CodeIgniter development, consider:
- Visual Studio Code with PHP extensions
- PhpStorm (premium IDE with excellent PHP support)
- Sublime Text with PHP packages
For VS Code, install these extensions:
- PHP Intelephense
- PHP Debug
- PHP DocBlocker
- EditorConfig
Step 10: Security Enhancements
Implement these additional security measures.
Disabling Directory Listings
Apache’s directory listing feature should be disabled (already done in our virtual host configuration). Verify by creating an empty directory and attempting to access it.
Protecting Sensitive Files
Add protection for configuration and system files:
sudo nano /var/www/ci4app/public/.htaccess
Add these rules:
# Deny access to dot files
<FilesMatch "^\.">
Order allow,deny
Deny from all
</FilesMatch>
# Deny access to composer files
<FilesMatch "composer\.(json|lock)">
Order allow,deny
Deny from all
</FilesMatch>
Security Headers Configuration
Add security headers in .htaccess
:
# Security headers
<IfModule mod_headers.c>
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header set Content-Security-Policy "default-src 'self'"
</IfModule>
CSRF Protection Setup
CodeIgniter includes CSRF protection. Ensure it’s enabled in your application:
sudo nano /var/www/ci4app/app/Config/Filters.php
Verify that the CSRF filter is enabled:
public $globals = [
'before' => [
// ...
'csrf',
// ...
],
// ...
];
Step 11: Performance Optimization
Optimize your installation for better performance.
Enabling PHP Opcode Caching
Install and enable OPcache:
sudo dnf install php-opcache -y
Configure OPcache:
sudo nano /etc/php.d/10-opcache.ini
Adjust these settings:
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
Apache Performance Tuning
Edit Apache configuration:
sudo nano /etc/httpd/conf/httpd.conf
Add or modify:
# Enable compression
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
# Enable caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
Database Query Optimization
Configure your database settings for better performance:
sudo nano /var/www/ci4app/app/Config/Database.php
Enable query caching:
public $default = [
// ...
'DBDebug' => true,
'cacheOn' => true,
'cacheDir' => '',
// ...
];
Congratulations! You have successfully installed CodeIgniter. Thanks for using this tutorial for installing CodeIgniter PHP framework on your Fedora 42 Linux system. For additional help or useful information, we recommend you check the official CodeIgniter website.