FedoraRHEL Based

How To Install CodeIgniter on Fedora 43

Install CodeIgniter on Fedora 43

CodeIgniter stands as one of the most elegant PHP frameworks for developers who value simplicity without sacrificing power. This lightweight framework has earned its reputation through years of helping developers build robust web applications with minimal configuration. If you’re running Fedora 43, you’re working with a cutting-edge Linux distribution that provides excellent support for modern PHP development.

This comprehensive guide walks you through every step of installing CodeIgniter 4 on Fedora 43. You’ll configure Apache, set up PHP with necessary extensions, install MariaDB, and deploy CodeIgniter using Composer. By the end, you’ll have a fully functional development environment ready for building your next web application.

Understanding CodeIgniter and System Requirements

CodeIgniter 4 represents a complete rewrite of the framework, bringing modern PHP practices while maintaining the simplicity that made the original version popular. The framework requires PHP 7.4 or higher, though PHP 8.0 or later is strongly recommended for better performance and security features.

Your server needs several PHP extensions to run CodeIgniter properly. The intl extension handles internationalization, while mbstring manages multibyte string operations. The json extension processes JSON data, and you’ll need database-specific extensions like mysqli or mysqlnd depending on your database choice.

Fedora 43 serves as an excellent platform for PHP development. This distribution ships with recent package versions and maintains robust security updates. The DNF package manager simplifies software installation and dependency resolution.

Prerequisites and Initial System Preparation

Before diving into the installation, ensure your Fedora 43 system is current. Open your terminal and run:

sudo dnf update -y

This command updates all installed packages to their latest versions. The update process may take several minutes depending on your internet connection and the number of packages requiring updates.

You’ll need root or sudo privileges throughout this tutorial. Most commands require elevated permissions to install packages and modify system configurations. If you’re working on a remote server, ensure you have SSH access configured properly.

Check your current system version to verify you’re running Fedora 43:

cat /etc/fedora-release

Installing Apache Web Server

Apache httpd serves as the foundation of your web server stack. Install it using DNF:

sudo dnf install httpd -y

The installation pulls in all necessary dependencies automatically. Once installed, start the Apache service:

sudo systemctl start httpd

Enable Apache to start automatically on system boot:

sudo systemctl enable httpd

These commands ensure your web server runs continuously, even after system reboots.

Configuring the Firewall

Fedora’s firewall blocks incoming HTTP and HTTPS traffic by default. Open these ports to allow web traffic:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

The --permanent flag saves these rules across reboots. The reload command applies the changes immediately.

Test your Apache installation by opening a web browser and navigating to your server’s IP address or localhost. You should see the default Fedora Apache test page.

Basic Apache Configuration

Apache’s main configuration file resides at /etc/httpd/conf/httpd.conf. Open it with your preferred text editor:

sudo nano /etc/httpd/conf/httpd.conf

Set the ServerName directive to prevent startup warnings:

ServerName localhost

You can also configure ServerAdmin with your email address:

ServerAdmin admin@example.com

Save the file and restart Apache to apply changes.

Installing PHP and Required Extensions

Fedora 43 repositories include PHP 8.x by default. Install PHP along with Apache integration:

sudo dnf install php php-cli php-fpm -y

This installs PHP, the command-line interface, and FastCGI Process Manager.

Installing CodeIgniter Dependencies

CodeIgniter requires several PHP extensions to function correctly. Install them all at once:

sudo dnf install php-mysqlnd php-mbstring php-intl php-json php-xml php-curl php-zip php-gd -y

Each extension serves a specific purpose:

  • php-mysqlnd: MySQL Native Driver for database connectivity
  • php-mbstring: Multibyte string handling for international characters
  • php-intl: Internationalization functions
  • php-json: JSON encoding and decoding
  • php-xml: XML parsing and manipulation
  • php-curl: HTTP requests to external services
  • php-zip: ZIP archive handling
  • php-gd: Image manipulation capabilities

Verifying Your PHP Installation

Check the installed PHP version:

php -v

List all loaded PHP extensions:

php -m

Create a phpinfo test file to view detailed PHP configuration:

sudo nano /var/www/html/info.php

Add this content:

<?php
phpinfo();
?>

Access http://your-server-ip/info.php in your browser to see comprehensive PHP information. Delete this file after verification as it exposes system details.

Optimizing PHP Configuration

Edit the PHP configuration file:

sudo nano /etc/php.ini

Adjust these settings for better CodeIgniter performance:

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

Restart Apache to apply PHP configuration changes:

sudo systemctl restart httpd

Installing and Configuring MariaDB

MariaDB provides a reliable, open-source database solution. Install the server:

sudo dnf install mariadb-server -y

Start and enable the MariaDB service:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Securing Your Database

Run the security script to harden your installation:

sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disable remote root login, and remove test databases. These steps significantly improve database security.

Creating the CodeIgniter Database

Log into MariaDB as root:

sudo mysql -u root -p

Create a database for your CodeIgniter application:

CREATE DATABASE ci4_database;

Create a dedicated database user with appropriate privileges:

CREATE USER 'ci4_user'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON ci4_database.* TO 'ci4_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace strong_password_here with a secure password. Never use simple passwords for production databases.

Installing Composer

Composer simplifies PHP dependency management and offers the cleanest way to install CodeIgniter. Install it from Fedora repositories:

sudo dnf install composer -y

Verify the installation:

composer --version

Composer handles all CodeIgniter dependencies automatically, ensuring you always have compatible package versions.

Downloading and Installing CodeIgniter

Navigate to the web directory:

cd /var/www

Create a new CodeIgniter 4 project using Composer:

sudo composer create-project codeigniter4/appstarter ci4app

This command downloads CodeIgniter 4 and all dependencies, creating a project named ci4app. The process takes a few minutes depending on your connection speed.

Understanding the Directory Structure

CodeIgniter organizes files logically:

  • app/: Contains your application code (controllers, models, views)
  • public/: The web-accessible directory (document root)
  • writable/: Stores logs, cache, and uploaded files
  • system/: Framework core files
  • vendor/: Composer dependencies

The public directory should serve as your document root for security. This prevents direct access to application files.

Configuring Apache Virtual Host

Create a new virtual host configuration for your CodeIgniter application:

sudo nano /etc/httpd/conf.d/ci4app.conf

Add this configuration:

<VirtualHost *:80>
    ServerName ci4app.local
    ServerAdmin admin@example.com
    DocumentRoot /var/www/ci4app/public
    
    <Directory /var/www/ci4app/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog /var/log/httpd/ci4app-error.log
    CustomLog /var/log/httpd/ci4app-access.log combined
</VirtualHost>

The DocumentRoot points to the public directory. The AllowOverride All directive enables .htaccess files, which CodeIgniter uses for URL rewriting.

Enabling mod_rewrite

CodeIgniter requires mod_rewrite for clean URLs. Enable it:

sudo dnf install mod_rewrite -y

Most Fedora Apache installations include this module by default.

Setting Up Local Domain Access

Edit your hosts file to access the application via a friendly domain:

sudo nano /etc/hosts

Add this line:

127.0.0.1   ci4app.local

Test your Apache configuration for syntax errors:

sudo apachectl configtest

If it returns “Syntax OK,” restart Apache:

sudo systemctl restart httpd

Setting Proper File Permissions

Correct file permissions prevent security vulnerabilities while ensuring Apache can access necessary files. Change ownership to the Apache user:

sudo chown -R apache:apache /var/www/ci4app

Set directory permissions:

sudo chmod -R 755 /var/www/ci4app

The writable directory needs more permissive settings:

sudo chmod -R 775 /var/www/ci4app/writable

Handling SELinux

Fedora enables SELinux by default. Set appropriate security contexts for web directories:

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/ci4app/writable(/.*)?"
sudo restorecon -Rv /var/www/ci4app/

These commands allow Apache to write to necessary directories while maintaining SELinux protection.

Configuring CodeIgniter Environment

CodeIgniter uses environment files for configuration. Copy the example file:

sudo cp /var/www/ci4app/env /var/www/ci4app/.env

Edit the environment file:

sudo nano /var/www/ci4app/.env

Set your environment to development:

CI_ENVIRONMENT = development

Development mode displays detailed errors, helping you debug issues. Switch to production mode for live sites.

Configure your database connection:

database.default.hostname = localhost
database.default.database = ci4_database
database.default.username = ci4_user
database.default.password = strong_password_here
database.default.DBDriver = MySQLi

Set your base URL:

app.baseURL = 'http://ci4app.local/'

The base URL must match your virtual host configuration.

Testing Your Installation

Open your browser and navigate to http://ci4app.local. You should see the CodeIgniter welcome page displaying “Welcome to CodeIgniter 4!” This confirms successful installation.

Creating a Test Controller

Create a simple controller to verify routing works:

sudo nano /var/www/ci4app/app/Controllers/Test.php

Add this code:

<?php

namespace App\Controllers;

class Test extends BaseController
{
    public function index()
    {
        return "CodeIgniter is working perfectly!";
    }
}

Access http://ci4app.local/test in your browser. You should see your test message.

Checking Logs

If something goes wrong, check error logs. Apache logs reside in /var/log/httpd/. CodeIgniter writes application logs to /var/www/ci4app/writable/logs/.

Implementing Security Best Practices

Security should never be an afterthought. Enable CSRF protection in app/Config/Filters.php. CodeIgniter 4 includes CSRF protection by default.

Configure XSS filtering to sanitize user input automatically. Always validate and sanitize data before processing.

For production environments, move your .env file outside the web root or ensure it’s protected by .htaccess. Never commit .env files to version control.

Consider implementing HTTPS with SSL certificates. Let’s Encrypt provides free SSL certificates, and configuring HTTPS protects data in transit.

Troubleshooting Common Issues

404 Errors on Routes: Verify mod_rewrite is enabled and AllowOverride All is set in your virtual host configuration. Check that the .htaccess file exists in the public directory.

Permission Denied: Review file ownership and permissions. Ensure Apache owns the CodeIgniter directory and SELinux contexts are correct.

Blank White Screen: Enable error display in development mode. Check PHP error logs at /var/log/php-fpm/www-error.log and Apache error logs.

Database Connection Failures: Verify MariaDB is running with sudo systemctl status mariadb. Double-check database credentials in your .env file.

Optimizing Performance

Enable PHP OPcache for better performance. Edit /etc/php.d/10-opcache.ini:

opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000

Configure Apache’s mod_deflate to compress responses, reducing bandwidth usage. Enable browser caching headers to improve load times for returning visitors.

Congratulations! You have successfully installed CodeIgniter. Thanks for using this tutorial for installing CodeIgniter PHP framework on your Fedora 43 Linux system. 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

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button