,

How to Set Up CodeIgniter 4 in Docker on Ubuntu (Step-by-Step Guide)

Set up CodeIgniter 4 in Docker on Ubuntu—no vague errors, no missing modules. Just a working dev stack with full debug and ethical hacking potential.

Calista deploys CodeIgniter 4 from the rooftops — because ethical hackers don’t always work in offices.

Most CodeIgniter 4 tutorials ignore the intl trap. Ours doesn’t — because you actually want it to work.

Back in 2005, I was SSH’ing into fresh servers and manually configuring every inch—Apache, PHP, MySQL, the works. It wasn’t just a habit; it was a rite of passage.

Over the years, I got so good at it I stopped questioning whether there was another way. The command line was my comfort zone.

But then Composer showed up. And Docker? It wasn’t just a tool—it was a reckoning.

Setting up CodeIgniter 4 used to take me hours of tweaking and permission-fiddling. Now? Minutes. In a container. Reproducible, portable, and finally, foolproof. (Okay, almost.)

This guide walks you through that exact transition—how to go from traditional installs to a fully Dockerized CodeIgniter 4 setup on Ubuntu. If you’ve ever wrestled with a blank screen, missing PHP modules, or Apache refusing to behave, you’re going to want to read this one line by line.

Let’s containerize the old-school way—smarter, cleaner, and ethically hackable.

What Is CodeIgniter 4 and Why Use Docker?

A Primer on CodeIgniter 4 and Docker

CodeIgniter 4 is a lightweight, powerful PHP framework designed for developers who want fast, elegant web apps without the bloat. It’s the next-gen of the popular CodeIgniter framework, packed with modern PHP features while retaining simplicity.

Docker is a containerization platform that lets you package your app and its environment into a portable, consistent unit. It solves the “works on my machine” problem and speeds up deployment, testing, and scaling.

Together, Docker and CodeIgniter 4 give you a robust, scalable web development setup that’s easy to build, ship, and maintain.

· · ─ ·𖥸· ─ · ·

Benefits of Using CodeIgniter 4 with Docker

Why Combine Docker with CodeIgniter 4?

  • Consistency: Docker containers behave the same everywhere — from your laptop to your production server.
  • Speed: Spin up development environments in seconds without complicated installs.
  • Isolation: Keep dependencies clean and avoid “dependency hell.”
  • Portability: Share your environment with teammates or deploy to any cloud platform.
  • Troubleshooting: Docker makes it easier to debug environment issues that often plague PHP apps.
  • Open Source Friendly: Leverage FOSS tools and workflows without vendor lock-in.

· · ─ ·𖥸· ─ · ·

Real-World Applications

How NGOs, Governments, Businesses, and Enthusiasts Use Dockerized CodeIgniter 4

  • NGOs: Quickly deploy secure apps for community data collection, resource management, and transparency dashboards with minimal overhead.
  • Government: Build maintainable internal tools and public-facing portals with consistent environments for development and testing.
  • Businesses: Accelerate web app development cycles with CI/CD-ready Docker containers that integrate easily with microservices.
  • Students & Tech Enthusiasts: Learn modern web dev practices and containerization while exploring PHP frameworks in a hands-on way.
  • Bloggers & Content Creators: Run customizable CMS-like apps or API backends without worrying about server config or PHP version conflicts.

This tutorial will guide you through the entire process of installing Docker on Ubuntu, setting up a LAMP (Linux, Apache, MySQL, PHP) container, and running CodeIgniter 4 inside it. It includes key troubleshooting tips based on real-world hiccups you may encounter.

· · ─ ·𖥸· ─ · ·

How to Install and Set Up Dockerized CodeIgniter 4 on Ubuntu

Getting CodeIgniter 4 up and running on your local Ubuntu machine has never been easier thanks to Docker. This setup streamlines the traditionally complex process of configuring web servers, PHP, and dependencies by packaging everything inside lightweight containers. In this section, you’ll learn step-by-step how to install Docker and Docker Compose, prepare your project directory and configuration files, and launch a fully functional CodeIgniter 4 environment. Whether you’re a developer, student, or hobbyist, this guide simplifies your development workflow and ensures your environment is consistent and reproducible across different machines.

Prerequisites

  • Ubuntu 20.04 or later
  • User with sudo privileges
  • Basic understanding of terminal commands

1. Install Docker and Docker Compose

sudo apt update
sudo apt install -y docker.io docker-compose
sudo systemctl enable docker
sudo usermod -aG docker $USER
newgrp docker

Test Docker:

docker --version
docker run hello-world

2. Create Your Project Directory

mkdir -p ~/ci_test/app
cd ~/ci_test

3. Dockerfile for LAMP + CodeIgniter 4

Create a Dockerfile inside ~/ci_test/app/:

FROM php:8.1-apache

# Install PHP extensions
RUN apt-get update && apt-get install -y \
    libicu-dev \
    zip unzip git \
    && docker-php-ext-install mysqli intl

# Enable Apache mod_rewrite
RUN a2enmod rewrite

# Copy Apache config
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf

# Set permissions for app
RUN chown -R www-data:www-data /var/www/html \
    && chmod -R 755 /var/www/html

EXPOSE 80

CMD ["apache2-foreground"]

4. Apache Virtual Host Config

Create 000-default.conf in the same app/ folder:

<VirtualHost *:80>
    DocumentRoot /var/www/html/ci4/public

    <Directory /var/www/html/ci4/public>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

5. Docker Compose File

Create docker-compose.yml in ~/ci_test:

version: '3.8'

services:
  app:
    build: ./app
    container_name: ci4-app
    ports:
      - "8080:80"
    volumes:
      - ./app/ci4:/var/www/html/ci4

6. Install CodeIgniter 4

cd app
composer create-project codeigniter4/appstarter ci4

7. Enable Development Mode

CodeIgniter’s default error handling is vague. Enable full debug output by creating/editing the .env file:

cp ci4/env ci4/.env
nano ci4/.env

Uncomment and change:

CI_ENVIRONMENT = development

8. Build and Run the Container

docker-compose up --build

Open in your browser: http://localhost:8080

You should see the CodeIgniter 4 welcome page.

· · ─ ·𖥸· ─ · ·

Organizing your project files clearly is essential to maintain a clean, scalable, and manageable Dockerized CodeIgniter 4 environment. Here’s a recommended file structure that keeps your Docker configuration, CodeIgniter app, and Apache settings neatly separated for easy navigation and future updates.

ci_test/                               # Root project folder
├── app/                            # Docker build context and config files
│   ├── Dockerfile              # Dockerfile for PHP-Apache + intl extension
│   ├── 000-default.conf    # Apache virtual host configuration
│   └── ci4/                        # Your CodeIgniter 4 application files (mounted volume)
│       ├── app/
│       ├── public/
│       ├── system/
│       └── writable/
├── docker-compose.yml    # Compose file to orchestrate container

Explanation of Key Components

  • app/Dockerfile: This file defines the Docker image for your PHP environment including necessary PHP extensions and Apache modules.
  • app/000-default.conf: Custom Apache configuration to serve your CodeIgniter 4 public directory and enable URL rewriting.
  • app/ci4/: This folder contains the CodeIgniter 4 project files installed via Composer. It is mounted inside the container at /var/www/html/ci4.
  • docker-compose.yml: Defines your service configurations, ports, and volume mounts for Docker Compose to build and run your container.

Keeping this structure clean and consistent helps avoid confusion and makes your Dockerized CodeIgniter 4 setup easier to maintain and share.

· · ─ ·𖥸· ─ · ·

Troubleshooting

1. Blank Page or Whoops Error

Ensure .env is set to development to display useful error messages:

CI_ENVIRONMENT = development

2. “Class ‘Locale’ not found” Error

Means the intl PHP extension is missing. Confirm this line is in your Dockerfile:

RUN apt-get install -y libicu-dev && docker-php-ext-install intl

Then rebuild:

docker-compose build --no-cache

3. Public Directory Lists Files Instead of Running PHP

Make sure Apache is pointing to the correct path and executing PHP:

  • DocumentRoot must be /var/www/html/ci4/public
  • .htaccess must exist in public/
  • Apache must allow .htaccess:
<Directory /var/www/html/ci4/public>
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Also test PHP by creating public/test.php:

<?php phpinfo();

If it downloads instead of rendering — PHP isn’t working.

· · ─ ·𖥸· ─ · ·

Why This Setup Matters (And Where to Go Next)

This wasn’t just a Docker tutorial—it was a paradigm shift. We took a classic PHP framework, CodeIgniter 4, and wrapped it in a container that actually works. No more mod_rewrite gotchas. No more missing intl modules. Just pure development velocity.

You now have a fast, local dev stack ready for rapid prototyping, secure API development, or even OSINT dashboards—built the open-source way.

If you found this guide useful, there’s more coming.

👉 Subscribe to DevDigest for weekly how-to’s, FOSS-powered security tooling, and ethical hacking workflows straight from the trenches.

Let’s build leaner, break less, and code like it’s 2025.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments (

)