
CodeIgniter remains one of the most practical PHP frameworks for teams that want a fast, lightweight application stack without the overhead of a large monolithic framework. On Fedora 45, installing it is straightforward, but the difference between a working development project and a reliable production deployment usually comes down to details: PHP-FPM permissions, SELinux labels, firewall rules, database credentials, and sane caching.
This guide walks through a complete CodeIgniter 4 installation on Fedora 45 using Apache, PHP-FPM, MariaDB, and Composer. It also covers the configuration choices that matter once real traffic starts arriving.
Prerequisites
Before starting, confirm that you have:
- A Fedora 45 server or workstation with root or sudo access.
- A domain name pointed to the server, if you plan to deploy publicly.
- At least 1 GB RAM for a minimal test environment; 2 GB or more is more comfortable for Composer, database operations, and concurrent PHP workers.
- Basic familiarity with the terminal.
Fedora 45 provides PHP through its official repositories. The default PHP branch is PHP 8.5, which requires CodeIgniter 4.7.0 or later. CodeIgniter 4 itself requires PHP 8.2 or newer, so Fedora’s default package is a good fit for a new installation.
Check the operating system and available updates first:
cat /etc/fedora-release
sudo dnf upgrade --refresh -y
Keeping the base system current before installing a web stack avoids avoidable package conflicts and ensures you receive current security fixes.
Install the LAMP Stack
For most CodeIgniter deployments, Apache with PHP-FPM is a dependable default. Apache handles incoming HTTP requests, while PHP-FPM executes PHP in separate worker processes. This separation makes resource tuning easier and reduces the chance that a slow PHP request blocks the entire web server.
Install Apache, PHP-FPM, MariaDB, Composer, and the extensions commonly needed by CodeIgniter applications:
sudo dnf install -y \
httpd \
mod_ssl \
mod_http2 \
php \
php-cli \
php-fpm \
php-mysqlnd \
php-pgsql \
php-gd \
php-intl \
php-mbstring \
php-xml \
php-bcmath \
php-sodium \
php-pecl-zip \
php-pecl-apcu \
mariadb-server \
composer \
git \
unzip
The packages above cover the common CodeIgniter use cases:
php-mysqlnd: MySQL and MariaDB database connectivity.php-pgsql: PostgreSQL support, useful if your application uses PostgreSQL.php-intl: Internationalization and locale-aware formatting.php-mbstring: Multibyte string handling.php-xml: XML processing.php-gd: Image manipulation.php-pecl-zip: ZIP archive support.php-pecl-apcu: Local object caching for suitable workloads.composer: Dependency management and CodeIgniter project creation.
Fedora’s official documentation also identifies mariadb-server as the standard package for installing MariaDB from the Fedora repositories. PHP packages on Fedora are installed through DNF, and the PHP project documents php, php-common, and php-fpm as the core packages for a typical server installation.
Verify the installed versions:
php -v
composer --version
httpd -v
mariadb --version
You should see PHP 8.5.x on a current Fedora 45 system. Fedora 45 ships PHP 8.5 through its official repositories, and the available patch version may change as Fedora publishes updates.
Start and Enable Services
Enable the services so they start automatically after a reboot:
sudo systemctl enable --now httpd
sudo systemctl enable --now php-fpm
sudo systemctl enable --now mariadb
Check their status:
sudo systemctl status httpd --no-pager
sudo systemctl status php-fpm --no-pager
sudo systemctl status mariadb --no-pager
If Apache is running correctly, httpd should report active (running). If it does not, inspect the logs before changing configuration files:
sudo journalctl -u httpd -b --no-pager
sudo tail -n 100 /var/log/httpd/error_log
Secure MariaDB
A fresh MariaDB installation should never be left with default settings in a production environment. Run the security script:
sudo mysql_secure_installation
Answer the prompts according to your environment. For a dedicated production database server, set a strong root password, remove anonymous users, disallow remote root login, and remove the test database.
Then create a dedicated database and application user. Avoid using the database root account from CodeIgniter.
sudo mysql
Inside the MariaDB shell:
CREATE DATABASE codeigniter_app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'ci_user'@'localhost' IDENTIFIED BY 'use-a-long-random-password';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER
ON codeigniter_app.*
TO 'ci_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Using a limited database user is not just a security habit. It reduces the blast radius if the application is compromised. A web application normally does not need global administrative privileges.
For a local test database, SQLite can also be useful because it requires no separate database service. For a production application with concurrent writes, MariaDB or PostgreSQL is usually the better choice.
Install Composer
Fedora provides Composer through DNF, which is convenient for system-level package management. Fedora’s current Composer package is maintained through the distribution’s update system.
Verify it:
composer --version
CodeIgniter 4 requires Composer 2.0.14 or later. If the Fedora package is older than that on your system, update the distribution or install Composer through its official installer.
Avoid running Composer as root when possible. Composer executes third-party scripts during dependency installation, and running it with elevated privileges can create unnecessary security risk. Create a normal deployment user for application work:
sudo adduser deploy
sudo usermod -aG wheel deploy
sudo su - deploy
On a single-administrator VPS, using your own non-root account is usually enough. On a team server, a dedicated deployment account with controlled SSH access is preferable.
Create a CodeIgniter Project
Choose a directory outside the web root for the application source. A common production layout places projects under /var/www while keeping the public entry point isolated.
Create the project:
sudo mkdir -p /var/www
sudo chown deploy:deploy /var/www
cd /var/www
composer create-project codeigniter4/appstarter codeigniter-app
Composer creates a project called codeigniter-app and installs the CodeIgniter 4 application starter. The official CodeIgniter documentation recommends Composer because it makes dependency updates easier.
Move into the project:
cd /var/www/codeigniter-app
Install production dependencies without development tools:
composer install --no-dev --optimize-autoloader
For local development, use:
composer install
The --no-dev flag prevents development packages such as testing tools from being installed in production. This keeps the vendor directory smaller and reduces the amount of code exposed on the server.
Configure the Environment
CodeIgniter 4 uses an .env file for environment-specific configuration. Copy the example file:
cp env .env
Open it:
nano .env
For a MariaDB-based application, configure values similar to these:
CI_ENVIRONMENT = production
database.default.hostname = localhost
database.default.database = codeigniter_app
database.default.username = ci_user
database.default.password = use-a-long-random-password
database.default.DBDriver = MySQLi
database.default.DBPrefix =
database.default.port = 3306
Never commit .env to Git. It contains credentials and environment-specific values. If the file is already tracked, remove it from version control:
git rm --cached .env
echo ".env" >> .gitignore
Set CI_ENVIRONMENT to production on a live server. Development mode displays detailed errors, which is helpful while coding but dangerous in production because it can expose paths, configuration details, and database errors.
Set Correct File Permissions
The web server must be able to read application files, but it should not own the source code. A practical production pattern is:
deployowns the application files.apachecan read them.- Writable directories are limited to cache, logs, uploads, and session storage where required.
Set ownership:
sudo chown -R deploy:deploy /var/www/codeigniter-app
Give the web server read access:
sudo chmod -R u=rwX,g=rX,o=rX /var/www/codeigniter-app
Identify the writable paths CodeIgniter uses:
find /var/www/codeigniter-app/writable -type d
Grant the Apache user write access only where necessary:
sudo chown -R apache:apache /var/www/codeigniter-app/writable
sudo chmod -R u=rwX,g=rX,o= /var/www/codeigniter-app/writable
Avoid setting 777 permissions. It is a common shortcut, but it gives every local user write access to application files. In a multi-user server environment, that is a serious problem.
Configure Apache
Create a virtual host for the application:
sudo nano /etc/httpd/conf.d/codeigniter-app.conf
Add:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/codeigniter-app/public
<Directory /var/www/codeigniter-app/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/codeigniter-app-error.log
CustomLog /var/log/httpd/codeigniter-app-access.log combined
</VirtualHost>
Replace example.com with your actual domain. The public directory is the only directory that should be directly exposed to the internet. It contains index.php, assets, and the front controller.
Validate the Apache configuration:
sudo httpd -t
Restart Apache:
sudo systemctl restart httpd
If you are testing locally without a domain, use the server IP address or add a temporary hosts entry:
sudo nano /etc/hosts
Example:
127.0.0.1 example.com www.example.com
Configure PHP-FPM
Fedora’s PHP-FPM pool configuration is usually located at:
/etc/php-fpm.d/www.conf
Check the current pool user and listen socket:
sudo grep -E '^(user|group|listen|listen.owner|listen.group)' /etc/php-fpm.d/www.conf
For a standard Apache and PHP-FPM setup, the pool commonly runs as apache. Confirm that Apache can communicate with the FPM socket:
sudo systemctl restart php-fpm
sudo systemctl status php-fpm --no-pager
For production tuning, review these settings in the pool file:
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
These values are examples, not universal settings. Calculate pm.max_children based on available RAM and the average memory used by each PHP worker.
For example, if each PHP-FPM worker uses approximately 60 MB and you want to reserve memory for Apache, MariaDB, the operating system, and caches, do not allocate every available megabyte to PHP. A server that runs out of memory can trigger the OOM killer, which may terminate MariaDB or Apache at the worst possible moment.
Check PHP memory limits:
php -i | grep -E 'memory_limit|upload_max_filesize|post_max_size'
For an application that handles file uploads, adjust PHP settings carefully:
sudo nano /etc/php.ini
Example values:
memory_limit = 256M
upload_max_filesize = 20M
post_max_size = 25M
max_execution_time = 60
Restart PHP-FPM after changes:
sudo systemctl restart php-fpm
Configure SELinux
Fedora uses SELinux by default. This is a strength, not an obstacle. SELinux prevents a compromised web process from reading or writing arbitrary locations on the server.
If Apache cannot read the application, check for SELinux denials:
sudo ausearch -m avc -ts recent
For a standard application under /var/www, apply the correct context:
sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/codeigniter-app(/.*)?"
sudo restorecon -Rv /var/www/codeigniter-app
For directories that Apache must write to, such as uploads or cache storage, use a writable context:
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/codeigniter-app/writable(/.*)?"
sudo restorecon -Rv /var/www/codeigniter-app/writable
If semanage is not installed:
sudo dnf install -y policycoreutils-python-utils
Do not disable SELinux simply because an application throws a permission error. Identify the denial, apply the appropriate context, and keep the protection enabled.
Open Firewall Ports
Fedora uses firewalld. For an HTTP-only test server, open port 80:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
For HTTPS, open port 443 as well:
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Verify the active rules:
sudo firewall-cmd --list-all
Do not expose MariaDB port 3306 to the public internet unless you have a specific, well-secured reason. For a single-server deployment, keep the database bound to localhost and allow only local connections.
Test CodeIgniter
Create a simple test route or use the default welcome page. First, confirm that the application can run through the PHP CLI:
cd /var/www/codeigniter-app
php spark serve --host 0.0.0.0 --port 8080
This starts CodeIgniter’s development server. It is useful for quick checks, but it is not a replacement for Apache, Nginx, or another production web server.
For the Apache setup, visit:
http://example.com
If you see the CodeIgniter welcome page, the installation is working.
If you see a blank page, check the PHP-FPM and Apache logs:
sudo tail -n 100 /var/log/httpd/error_log
sudo journalctl -u php-fpm -b --no-pager
Common Installation Problems
Blank White Page
A blank page usually means PHP failed before output could be sent. Check the logs first.
sudo tail -n 100 /var/log/httpd/error_log
sudo journalctl -u php-fpm -b --no-pager
Common causes include:
- Missing PHP extensions.
- Incorrect file permissions.
- SELinux denying access.
- A PHP syntax error in an application file.
- PHP-FPM not running.
Enable temporary error display only on a development machine:
php -d display_errors=1 -S localhost:8080
Never leave detailed PHP errors enabled on a public production server.
403 Forbidden
This often means Apache cannot read the application directory or SELinux is blocking access.
Check Apache permissions:
sudo -u apache test -r /var/www/codeigniter-app/public/index.php
Check SELinux denials:
sudo ausearch -m avc -ts recent
Apply the appropriate SELinux context as shown earlier. Avoid changing SELinux to permissive mode as a permanent solution.
Database Connection Error
Check that MariaDB is running:
sudo systemctl status mariadb --no-pager
Test the credentials:
mysql -u ci_user -p -h localhost codeigniter_app
If the connection works from the command line but CodeIgniter fails, inspect .env, especially the database name, username, password, host, and driver.
Composer Memory Errors
Composer can consume substantial memory while resolving dependencies. If you see memory allocation errors, increase available swap or run Composer on a machine with more RAM.
Check memory and swap:
free -h
swapon --show
For a small VPS, avoid installing unnecessary development packages in production. Use composer install --no-dev --optimize-autoloader.
Route Returns 404
If the homepage works but other routes return 404, ensure Apache can process .htaccess rules and that AllowOverride All is set for the public directory.
Also verify that mod_rewrite is enabled:
sudo httpd -M | grep rewrite
If it is not loaded:
sudo dnf install -y mod_rewrite
sudo systemctl restart httpd
Production Optimization
Use OPcache
OPcache stores compiled PHP bytecode in memory, reducing the need to recompile PHP files on every request. It is one of the highest-impact performance settings for PHP applications.
Check whether it is enabled:
php -m | grep -i opcache
Configure it in the PHP-FPM configuration:
sudo nano /etc/php.d/10-opcache.ini
A reasonable starting configuration:
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=20000
opcache.validate_timestamps=1
opcache.revalidate_freq=2
On a deployment pipeline where code is replaced atomically, opcache.validate_timestamps=0 can improve performance, but it requires a PHP-FPM reload after every deployment. Do not enable it blindly on a server where files are edited directly.
Restart PHP-FPM:
sudo systemctl restart php-fpm
Cache Expensive Operations
CodeIgniter supports caching, and production applications should use it for data that does not need to be recalculated on every request. Examples include navigation menus, product categories, configuration values, and expensive report queries.
APCu is useful for single-server caching. Redis or Memcached becomes more valuable when you run multiple application servers and need shared cache storage.
For a traffic spike, caching can protect the database from unnecessary repeated queries. A page that takes 300 ms when uncached may serve in a few milliseconds when the result is already in cache.
Tune MariaDB Carefully
Do not copy large MariaDB tuning configurations from the internet without measuring your workload. Start with conservative values, monitor performance, and adjust based on real usage.
Check current status:
sudo mysqladmin -p status
sudo mysql -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"
For a dedicated database server, the InnoDB buffer pool is often the most important setting. It should fit the working set of frequently accessed data and indexes, while leaving memory for the operating system and other processes.
Avoid allocating all RAM to the database. The server still needs memory for PHP-FPM, Apache, backups, logs, and system operations.
Use HTTPS
TLS is standard for production websites. Install Certbot and obtain a certificate from Let’s Encrypt:
sudo dnf install -y certbot python3-certbot-apache
sudo certbot --apache
Follow the prompts to select the domain and configure automatic redirection. Certbot can renew certificates automatically, but verify the renewal process with:
sudo certbot renew --dry-run
Deployment Workflow
For a production application, avoid editing files directly on the server. A simple and reliable workflow is:
- Develop locally or in a staging environment.
- Commit code to Git.
- Run tests and static analysis.
- Deploy to a release directory.
- Run database migrations.
- Reload PHP-FPM.
- Verify health checks.
A basic deployment sequence might look like this:
cd /var/www/codeigniter-app
git pull origin main
composer install --no-dev --optimize-autoloader
php spark migrate
sudo systemctl reload php-fpm
For higher-availability deployments, use a release-directory pattern. Deploy a new release to a timestamped folder, run migrations, update a symbolic link, and reload PHP-FPM. This makes rollbacks faster and reduces downtime during deployments.