How to Install CodeIgniter 4: Step-by-Step Guide for Beginners

Reading Time: 2 minutes

CodeIgniter 4 is a lightweight and powerful PHP framework designed for developers who want speed, simplicity, and performance.
It follows modern PHP standards while remaining easy to learn, making it a great choice for small to medium-sized web applications.

In this guide, you’ll learn how to install CodeIgniter 4 step by step using the recommended methods.


Prerequisites for Installing CodeIgniter 4

Before installing CodeIgniter 4, ensure your system meets the following requirements:

  • PHP (version 8.1 or higher recommended)
  • Composer
  • Web server (Apache or Nginx)
  • Database (MySQL / MariaDB)

Check PHP Version


php -v

Step 1: Install Composer

Composer is required to install and manage CodeIgniter 4 dependencies.

Download Composer


php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Install Composer Globally


php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Verify installation:


composer -V

Step 2: Install CodeIgniter 4 Using Composer

Create a New Project


composer create-project codeigniter4/appstarter myapp

This command:

  • Downloads CodeIgniter 4
  • Sets up the project structure
  • Installs required dependencies

Move into the project directory:


cd myapp

Step 3: Configure Environment File

Copy the example environment file:


cp env .env

Open .env and update:


CI_ENVIRONMENT = development

Step 4: Set Application Base URL

Edit .env:


app.baseURL = 'http://localhost:8080/'

Setting the base URL helps with routing and asset loading.


Step 5: Configure Database Connection

Update database settings in .env:


database.default.hostname = localhost
database.default.database = myapp_db
database.default.username = myapp_user
database.default.password = your_password
database.default.DBDriver = MySQLi

Step 6: Run CodeIgniter 4 Development Server

Start the built-in server:


php spark serve

Open in browser:


http://localhost:8080

You should see the CodeIgniter 4 welcome page 🎉


Alternative Method: Manual Installation (ZIP)

  1. Download the latest CodeIgniter 4 from the official website
  2. Extract files into your web directory
  3. Configure .env and base URL
  4. Set permissions for writable folder

⚠️ Composer installation is strongly recommended for updates and security.


Common Issues & Fixes

1. Writable Directory Permission Error


chmod -R 775 writable

2. Missing PHP Extensions

Install:


php-intl php-mbstring php-curl php-xml

3. Base URL Not Working

Make sure app.baseURL matches your server URL exactly.


Why Choose CodeIgniter 4?

CodeIgniter 4 is preferred because:

  • Lightweight and fast
  • Simple learning curve
  • Modern PHP standards
  • Minimal configuration
  • Excellent performance

It’s ideal for small projects, APIs, and high-performance apps.


Final Thoughts

Installing CodeIgniter 4 is quick and straightforward, especially using Composer.
If you prefer a lightweight framework with flexibility and speed, CodeIgniter 4 is an excellent choice.

Share