Installation & Setup
Before you can build anything with CodeIgniter 4, you need a working local environment: the right PHP version, a handful of PHP extensions, and a copy of the framework itself. The officially supported (and by far the easiest) way to get a new project running is through Composer. This page walks through every step, from checking your server requirements to seeing the CodeIgniter welcome page in your browser.
1. Server Requirements
CodeIgniter 4 has modest requirements compared to many modern frameworks, which is part of why it runs comfortably on ordinary shared hosting. Before installing, confirm your environment meets these:
| Requirement | Details |
|---|---|
| PHP version | PHP 7.4 or newer (PHP 8.0+ recommended for current CI4 releases) |
intl extension | Required — used for internationalization and locale-aware formatting |
mbstring extension | Required — used throughout the framework for safe multi-byte string handling |
json extension | Required — nearly always enabled by default |
mysqlnd (or another DB driver) | Required only if you plan to use the database layer, which almost every real project does |
| A webserver | Apache or Nginx (or PHP's own built-in development server for local work) |
You can check which extensions are enabled on your machine by running php -m from the
command line, or by loading a phpinfo() page, both of which are covered in the Core PHP track.
2. Installing via Composer
Composer is the standard PHP dependency manager, and it is the recommended way to install CodeIgniter 4.
If you're new to Composer, the Composer track on this site covers it from scratch — the short
version is that Composer downloads the framework and its dependencies into a vendor/ folder
and wires up autoloading for you automatically.
Run the following command from the folder where you want your new project to live:
composer create-project codeigniter4/appstarter my_project
This downloads the appstarter skeleton — a ready-to-run CodeIgniter 4 application
with sensible default configuration — into a new my_project folder. Once it finishes,
move into that folder for all further commands:
cd my_project
3. Starting the Built-in Development Server
CodeIgniter ships with its own command-line utility called spark, sitting right at the root of every project. One of its most immediately useful commands starts a lightweight development server without needing Apache or Nginx configured at all:
php spark serve
By default this starts serving your application at http://localhost:8080. Open that address
in a browser and, on a fresh install, you should see the CodeIgniter welcome page confirming everything
is wired up correctly. If port 8080 is already in use, you can specify a different one:
php spark serve --port 8081
4. The spark CLI Tool
spark is CodeIgniter's built-in command-line tool, and serve is just one of
the commands it offers. You will meet spark repeatedly throughout this track — it can
generate boilerplate files (controllers, models, migrations), run database migrations, and list every
registered route in your application, among many other things. For now, it's enough to know it exists
and lives at the project root as the spark file, invoked with php spark <command>.
To see every command spark supports, run:
php spark list
5. Setting the Base URL and Environment
Two places control how your application identifies its own environment and base URL: the .env
file at your project root, and app/Config/App.php. CodeIgniter ships with an env
file (no leading dot) as a template — copy it to .env to activate it:
cp env .env
Inside .env, two settings matter most when you're just getting started: the environment
name, and the base URL used to generate absolute links throughout your app.
# Switches error reporting, caching behaviour, and more
CI_ENVIRONMENT = development
# Used by base_url() and site_url() to build absolute links
app.baseURL = 'http://localhost:8080/'
Settings placed in .env override the matching properties in app/Config/App.php,
which is the underlying configuration class. You can also set the base URL directly in that file if you
prefer not to use .env:
<?php
namespace Config;
class App extends BaseConfig
{
public $baseURL = 'http://localhost:8080/';
}
CI_ENVIRONMENT set to development while building
locally — it enables detailed error pages and the built-in debug toolbar. Switch it to
production before deploying so users never see raw stack traces.6. Verifying Your Install
With the dev server running (or your virtual host pointed at the right folder), load the base URL in a browser. A correct install shows CodeIgniter's default welcome page, which includes the framework version number and confirms PHP, the environment, and routing are all functioning together. If you see a blank page or an error instead, double-check the PHP version and extensions from step 1 first — most fresh-install problems trace back to a missing extension or an incompatible PHP version.
7. Top-Level Project Folders
A freshly installed project has a handful of top-level folders. The next lesson digs into each one in depth, but it helps to know what they're for right away:
| Folder | Purpose |
|---|---|
app/ | Your application code — controllers, models, views, config, routes |
public/ | The actual web document root; only this folder (and its assets) should be exposed to the internet |
writable/ | Cache, logs, session data, and uploaded files — must be writable by the webserver |
tests/ | PHPUnit tests for your application |
vendor/ | Composer-managed dependencies, including the CodeIgniter framework itself |
app/ and how a request flows through the framework.