AlmaLinuxRHEL Based

How To Install CodeIgniter on AlmaLinux 10

Install CodeIgniter on AlmaLinux 10

Installing CodeIgniter on AlmaLinux 10 represents a powerful combination of enterprise-grade stability and modern web development capabilities. This comprehensive guide walks through every step required to successfully deploy CodeIgniter 4 on your AlmaLinux 10 server, ensuring optimal performance and security.

CodeIgniter continues to be one of the most popular PHP frameworks due to its simplicity, speed, and robust feature set. AlmaLinux 10, as an enterprise-ready Linux distribution that maintains full compatibility with Red Hat Enterprise Linux, provides the perfect foundation for hosting PHP applications in production environments. Whether you’re a system administrator, web developer, or DevOps professional, this guide provides the detailed instructions needed to create a fully functional CodeIgniter development environment.

Understanding CodeIgniter and AlmaLinux 10

CodeIgniter Framework Overview

CodeIgniter stands out as a powerful PHP framework that follows the Model-View-Controller (MVC) architectural pattern. Version 4 introduces significant improvements including modern PHP support, enhanced performance, and improved security features. The framework’s small footprint and clear documentation make it an excellent choice for developers seeking rapid application development without sacrificing functionality.

The framework’s architecture separates presentation logic from business logic, enabling cleaner code organization and easier maintenance. CodeIgniter 4 supports PHP 8.0 and later versions, providing access to modern language features while maintaining backward compatibility with existing applications.

Key benefits include built-in libraries for common tasks, flexible URI routing, comprehensive form and data validation, and robust security features. The framework’s emphasis on simplicity means developers can focus on building applications rather than wrestling with complex configuration requirements.

AlmaLinux 10 Platform Benefits

AlmaLinux 10 represents the latest evolution of this community-driven, enterprise-grade Linux distribution. Built as a 1:1 binary compatible replacement for Red Hat Enterprise Linux, it offers unparalleled stability and security for production environments. The distribution provides a 10-year support lifecycle, ensuring long-term reliability for web applications.

The platform includes enhanced security features, updated package repositories, and improved hardware support. These improvements make AlmaLinux 10 particularly well-suited for PHP development environments, offering the reliability needed for both development and production deployments. System requirements remain modest while providing robust performance capabilities.

System Requirements and Prerequisites

Hardware Requirements

Before beginning the installation process, ensure your system meets the minimum hardware specifications. AlmaLinux 10 requires at least 1GB of RAM, though 2GB or more is recommended for optimal performance when running web applications. Storage requirements include sufficient space for the operating system, CodeIgniter files, and application data.

Network connectivity is essential for downloading packages and dependencies during the installation process. Consider bandwidth requirements if you plan to deploy applications that handle significant traffic volumes.

Software Prerequisites

CodeIgniter 4 requires PHP version 7.4 or later, with PHP 8.1 or 8.3 recommended for optimal performance and security. Essential PHP extensions include intl, mbstring, and curl for proper framework functionality. The intl extension handles internationalization features, while mbstring provides multibyte string support.

Web server compatibility encompasses both Apache and Nginx configurations. Apache remains the most common choice due to its extensive documentation and .htaccess support. Database requirements include MySQL 5.7+, PostgreSQL 9.6+, or SQLite 3.8.3+ for data storage capabilities.

Composer serves as the recommended dependency manager for CodeIgniter installation and package management. This tool automates the process of downloading, installing, and managing PHP libraries and their dependencies.

Preparing AlmaLinux 10 Environment

System Updates and Security

Begin by updating your AlmaLinux 10 system to ensure you have the latest security patches and package definitions. Execute the following commands to perform a comprehensive system update:

sudo dnf update -y
sudo dnf upgrade -y

These commands update package definitions and upgrade installed packages to their latest versions. The process may take several minutes depending on your system’s current state and available updates.

Configure the firewall to allow web traffic while maintaining security. Enable HTTP and HTTPS services:

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

Establish proper user permissions and sudo access for development activities. Create a dedicated user account for web development if needed:

sudo useradd -m -s /bin/bash webdev
sudo usermod -aG wheel webdev

Repository Configuration

Install the EPEL repository to access additional packages not included in the base AlmaLinux repositories:

sudo dnf install epel-release -y

Add the Remi repository for access to modern PHP versions. The Remi repository provides up-to-date PHP packages optimized for enterprise Linux distributions:

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-10.rpm

Configure package manager preferences to prioritize stable releases while allowing access to newer versions when needed. This ensures system stability while providing flexibility for development requirements.

Essential Tools Installation

Install development tools and utilities required for web development:

sudo dnf groupinstall "Development Tools" -y
sudo dnf install git wget unzip nano -y

Git provides version control capabilities essential for modern development workflows. The wget utility enables downloading files from web sources, while unzip handles compressed archives. Include your preferred text editor for configuration file modifications.

Installing Web Server Components

Apache HTTP Server Installation

Install Apache HTTP Server using the DNF package manager:

sudo dnf install httpd -y

Start and enable the Apache service to ensure it runs automatically at system boot:

sudo systemctl start httpd
sudo systemctl enable httpd

Configure Apache for CodeIgniter by creating a virtual host configuration. Create a new configuration file:

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

Add the following virtual host configuration:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/html/codeigniter/public
    
    <Directory /var/www/html/codeigniter/public>
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog /var/log/httpd/codeigniter_error.log
    CustomLog /var/log/httpd/codeigniter_access.log combined
</VirtualHost>

This configuration sets up a basic virtual host for your CodeIgniter application with proper directory permissions and logging capabilities.

PHP Installation and Configuration

Install PHP 8.3 from the Remi repository for optimal CodeIgniter performance. First, reset any existing PHP modules:

sudo dnf module reset php -y

Enable the Remi repository for PHP 8.3:

sudo dnf module enable php:remi-8.3 -y

Install PHP and required extensions:

sudo dnf install -y php php-cli php-common php-fpm php-mysqlnd php-opcache php-xml php-mbstring php-curl php-gd php-json php-zip php-intl

Configure PHP settings for web development. Edit the PHP configuration file:

sudo nano /etc/php.ini

Adjust key settings for CodeIgniter:

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
date.timezone = America/New_York

Restart Apache to apply the new PHP configuration:

sudo systemctl restart httpd

Verify PHP installation by checking the version:

php -v

Database Setup

MySQL/MariaDB Installation

Install MariaDB server on AlmaLinux 10:

sudo dnf install mariadb-server -y

Start and enable the MariaDB service:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure the database installation by running the security script:

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.

Database Configuration for CodeIgniter

Create a dedicated database and user for your CodeIgniter application:

sudo mysql -u root -p

Execute the following SQL commands:

CREATE DATABASE codeigniter_db;
CREATE USER 'ci_user'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON codeigniter_db.* TO 'ci_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Test database connectivity to ensure proper configuration:

mysql -u ci_user -p codeigniter_db

CodeIgniter Installation Methods

Installation via Composer (Recommended)

Composer installation provides the most streamlined approach for CodeIgniter deployment. Install Composer globally on your system:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Verify Composer installation:

composer --version

Navigate to your web root directory and create a new CodeIgniter project:

cd /var/www/html
sudo composer create-project codeigniter4/appstarter codeigniter

This command downloads CodeIgniter 4 and all its dependencies, creating a complete project structure. The installation process automatically configures autoloading and sets up the basic application framework.

Set proper file permissions for the web server:

sudo chown -R apache:apache /var/www/html/codeigniter
sudo chmod -R 755 /var/www/html/codeigniter

Manual Installation Method

For environments where Composer isn’t available, manual installation provides an alternative approach. Download the latest CodeIgniter release from the official repository:

cd /tmp
wget https://github.com/codeigniter4/CodeIgniter4/archive/refs/tags/v4.6.1.zip

Extract the archive to your web directory:

sudo unzip v4.6.1.zip -d /var/www/html/
sudo mv /var/www/html/v4.6.1 /var/www/html/codeigniter

Configure file permissions and ownership:

sudo chown -R apache:apache /var/www/html/codeigniter
sudo chmod -R 755 /var/www/html/codeigniter

CodeIgniter Configuration

Environment Configuration

Create and configure the environment file for your CodeIgniter application:

cd /var/www/html/codeigniter
sudo cp env .env

Edit the environment file to set development mode and basic configuration:

sudo nano .env

Configure essential settings:

CI_ENVIRONMENT = development
app.baseURL = 'http://yourdomain.com'
app.indexPage = ''

database.default.hostname = localhost
database.default.database = codeigniter_db
database.default.username = ci_user
database.default.password = strong_password
database.default.DBDriver = MySQLi

Security and Performance Settings

Generate an encryption key for your application:

php spark key:generate

This command creates a secure encryption key and automatically updates your .env file. The encryption key is essential for session security and data protection.

Configure session settings for security:

sudo nano app/Config/Session.php

Adjust session configuration for production use:

public $driver = 'files';
public $cookieName = 'ci_session';
public $expiration = 7200;
public $savePath = WRITEPATH . 'session';
public $matchIP = false;
public $timeToUpdate = 300;
public $regenerateDestroy = false;

Testing and Verification

Initial Testing

Test your CodeIgniter installation by running the development server:

cd /var/www/html/codeigniter
php spark serve

This command starts CodeIgniter’s built-in development server on localhost:8080. Open your web browser and navigate to http://localhost:8080 to see the welcome page.

For Apache testing, navigate to your configured domain or IP address. You should see the CodeIgniter welcome screen, indicating successful installation.

Production Deployment Testing

Verify that URL rewriting works correctly by testing different routes. Create a test controller to ensure proper MVC functionality:

php spark make:controller TestController

Add a simple method to test routing:

<?php namespace App\Controllers;

class TestController extends BaseController
{
    public function index()
    {
        return view('test_view');
    }
}

Test database connectivity by creating a simple model and testing database operations.

Security Hardening

File System Security

Implement proper file permissions for CodeIgniter directories. The writable directory should be the only location with write permissions:

sudo chmod -R 755 /var/www/html/codeigniter
sudo chmod -R 777 /var/www/html/codeigniter/writable

Remove or secure sensitive files from public access:

sudo rm /var/www/html/codeigniter/public/index.php.bak
sudo chmod 600 /var/www/html/codeigniter/.env

Web Server Security

Configure Apache security headers and modules. Edit your virtual host configuration:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot /var/www/html/codeigniter/public
    
    <Directory /var/www/html/codeigniter/public>
        AllowOverride All
        Require all granted
    </Directory>
    
    Header always set X-Frame-Options DENY
    Header always set X-Content-Type-Options nosniff
    Header always set X-XSS-Protection "1; mode=block"
    
    ErrorLog /var/log/httpd/codeigniter_error.log
    CustomLog /var/log/httpd/codeigniter_access.log combined
</VirtualHost>

Enable necessary Apache modules:

sudo dnf install mod_headers -y
sudo systemctl restart httpd

Troubleshooting Common Issues

Installation Problems

PHP Extension Errors: If you encounter missing PHP extension errors, install the required extensions:

sudo dnf install php-intl php-mbstring php-curl -y
sudo systemctl restart httpd

Database Connection Issues: Verify database credentials in your .env file and test manual connection:

mysql -u ci_user -p codeigniter_db

Permission Problems: Ensure proper file ownership and permissions:

sudo chown -R apache:apache /var/www/html/codeigniter
sudo chmod -R 755 /var/www/html/codeigniter
sudo chmod -R 777 /var/www/html/codeigniter/writable

Performance and Configuration Issues

Memory Limit Errors: Increase PHP memory limit in php.ini:

memory_limit = 512M

Slow Page Load Times: Enable PHP OPcache for improved performance:

sudo nano /etc/php.ini

Configure OPcache settings:

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60

Debugging Techniques: Enable CodeIgniter debugging by setting CI_ENVIRONMENT to development and checking error logs:

sudo tail -f /var/log/httpd/codeigniter_error.log

Best Practices and Optimization

Development Best Practices

Implement version control for your CodeIgniter projects:

cd /var/www/html/codeigniter
git init
git add .
git commit -m "Initial CodeIgniter installation"

Organize your development environment with proper directory structure and naming conventions. Follow CodeIgniter’s coding standards and utilize the framework’s built-in libraries for common tasks.

Performance Optimization

Implement caching strategies to improve application performance. Configure file-based caching in your CodeIgniter application:

$cache = \Config\Services::cache();
$cache->save('key', 'value', 300);

Optimize database queries by using CodeIgniter’s Query Builder methods and avoiding unnecessary database calls. Enable database query caching for frequently accessed data.

Configure server-level optimizations including PHP-FPM for better resource management:

sudo systemctl enable php-fpm
sudo systemctl start php-fpm

Congratulations! You have successfully installed CodeIgniter. Thanks for using this tutorial for installing the CodeIgniter PHP framework on your AlmaLinux OS 10 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