CodeIgniter 4 is a lightweight PHP framework that follows the MVC pattern and is still actively maintained: version 4.7.0 arrived on February 1, 2026 and requires PHP 8.2 or higher, and the 4.7.4 patch in July 2026 focused on security fixes. This guide explains what CodeIgniter 4 is, what is new in the 4.7 series, how to set up a project, and the practices that keep a CodeIgniter app fast and secure.
Quick answer
- What it is: a small, fast, full-stack PHP framework with MVC, routing, validation, a database layer and a command-line tool called Spark.
- Current version: the 4.7 series. Version 4.7.0 was released on February 1, 2026 and needs PHP 8.2 or higher. Version 4.6.5 is the maintenance release for teams still on PHP 8.1.
- Install:
composer create-project codeigniter4/appstarter project-name - Authentication: use Shield, the official authentication and authorization package for CodeIgniter 4.
- Update often: the 4.7.4 release in July 2026 included security hardening for request handling, query builder escaping and file uploads, so run the latest patch.
- CodeIgniter 3 is the legacy version and gets mostly security updates. Start new projects on CodeIgniter 4.
What is CodeIgniter 4?
CodeIgniter 4 is an open-source PHP framework first released in February 2020. It is a rewrite of the older CodeIgniter 3, with namespaces, Composer support, a PSR-friendly structure and a modern command-line tool and it aims to stay light, fast and easy to learn, without the heavy setup of larger frameworks.
It works well for:
- Business websites, admin panels and dashboards
- REST APIs for mobile and single-page apps
- Projects on shared or low-cost hosting
- Teams that want a small framework and few moving parts
What is new in CodeIgniter 4.7
The 4.7 series is the biggest recent step for the framework. Highlights from the release notes and announcement:
- PHP 8.2 or higher is required. If you cannot upgrade PHP yet, stay on 4.6.5.
- Experimental FrankenPHP worker mode, which keeps the application in memory between requests for better performance. It is marked experimental, so test before using it in production.
- Signals, a new feature for handling process signals in command-line work.
- Better models and entities: stronger type hints, deep change tracking for objects and arrays in entities, correct conversion of entity arrays and primary key validation in models.
- Cache improvements: the cache interface gains methods such as
deleteMatching()andremember(). - Performance work in the HTTP client, including shared DNS cache and connections in CURLRequest.
Upgrade note: 4.7.0 includes breaking changes, such as new method requirements on interfaces and stricter handling of regex placeholders in validation. Read the upgrade guide, test in a staging copy and update to the newest 4.7 patch.
Key features of CodeIgniter 4
| Feature | What it gives you |
|---|---|
| MVC structure | Models for data, views for output, controllers for logic |
| Routing | Clear route definitions in app/Config/Routes.php, with route groups and filters |
| Validation | Built-in rules for forms and API input, with custom messages |
| Query Builder and Models | Safe database queries, plus CRUD helpers such as find, insert and update |
| Entities | Objects that represent database rows with casting and change tracking |
| Migrations and seeders | Version-controlled database changes |
| Filters | Run code before and after requests, for authentication, CSRF and rate checks |
| Spark CLI | Generate code, run migrations, start a dev server and run custom commands |
| Security helpers | CSRF protection, output escaping, secure sessions and a content security policy |
| Caching | Cache queries, pages and data with several drivers |
| Testing | Built-in testing helpers on top of PHPUnit |
| Debug Toolbar | Inspect queries, timing and requests during development |
Server requirements
- CodeIgniter 4.7.x: PHP 8.2 or higher
- CodeIgniter 4.6.x: PHP 8.1 or higher (use 4.6.5 or later)
- Required PHP extensions such as intl, mbstring and json, plus the extension for your database (for example mysqli or pdo)
- A web server pointed at the project’s
publicfolder
Check your host’s PHP version before you start. If you are choosing a host, see our guide to the best web hosting in India.
How to set up a CodeIgniter 4 project
- Install Composer, the PHP dependency manager.
- Create the project:
composer create-project codeigniter4/appstarter my-app
cd my-app- Copy the environment file: copy
envto.envand setCI_ENVIRONMENT = developmentwhile you build. - Start the dev server:
php spark serve- Open
http://localhost:8080to see the welcome page. - Configure the database in
.env, then create a migration and run it:
php spark make:migration CreatePosts
php spark migrateImportant: on a live server, point the web root to the public folder, not the project root, so your code, configuration and .env file are not reachable from the web.
Understanding MVC in CodeIgniter 4
- Model: talks to the database and holds data rules.
- View: the HTML the user sees. CodeIgniter 4 views are plain PHP files in
app/Views. It also includes a simple View Parser, and you can add a template engine such as Twig through a third-party package, but Twig is not built in. - Controller: receives the request, uses models, and returns a view or JSON.
A small working example: a posts page
1. Route (app/Config/Routes.php):
$routes->get('posts', 'Posts::index');
$routes->post('posts', 'Posts::create');2. Model (app/Models/PostModel.php):
<?php
namespace App\Models;
use CodeIgniter\Model;
class PostModel extends Model
{
protected $table = 'posts';
protected $primaryKey = 'id';
protected $allowedFields = ['title', 'body'];
protected $useTimestamps = true;
}3. Controller (app/Controllers/Posts.php):
<?php
namespace App\Controllers;
use App\Models\PostModel;
class Posts extends BaseController
{
public function index()
{
$posts = (new PostModel())->findAll();
return view('posts/index', ['posts' => $posts]);
}
public function create()
{
$rules = [
'title' => 'required|min_length[3]|max_length[150]',
'body' => 'required',
];
if (! $this->validate($rules)) {
return view('posts/index', [
'posts' => (new PostModel())->findAll(),
'validation' => $this->validator,
]);
}
(new PostModel())->insert($this->validator->getValidated());
return redirect()->to('/posts');
}
}4. View (app/Views/posts/index.php):
<?php foreach ($posts as $post): ?>
<h2><?= esc($post['title']) ?></h2>
<p><?= esc($post['body']) ?></p>
<?php endforeach; ?>Three things to notice: $allowedFields limits which columns can be written, validate() checks input before it reaches the database, and esc() escapes output to reduce cross-site scripting risk. Add <?= csrf_field() ?> inside any form that posts data, and keep the CSRF filter enabled.
Authentication with Shield
For login, registration, sessions, access tokens and permissions, use Shield, the official authentication and authorization package. Install and set it up with:
composer require codeigniter4/shield
php spark shield:setupShield avoids the risk of writing your own password and session handling. Check its documentation for the Shield version that matches your CodeIgniter and PHP versions.
CodeIgniter 4 best practices for 2026
- Stay on a supported PHP and framework version. Use PHP 8.2 or higher with CodeIgniter 4.7, and apply patch releases quickly. The 4.7.4 release was a security-focused patch.
- Serve only the public folder and keep
.env,appandwritableoutside web reach. - Set production mode. Use
CI_ENVIRONMENT = productionand turn off debug output so errors do not leak details. - Validate everything. Validate form input, API payloads and file uploads, and check upload type and size.
- Escape output with
esc()and keep the CSRF filter on for forms. - Use the Query Builder or models, never raw SQL built from user input.
- Use migrations for every database change so teams and servers stay in sync.
- Use Composer and commit
composer.lock, then update dependencies on a schedule. - Cache expensive work such as repeated queries and API calls.
- Write tests for models and key controllers, and run them before each deploy.
- Monitor and back up. If your site is ever compromised, see our guide on how to check if your PHP website was hacked and the PHP2Shell vulnerability guide.
CodeIgniter 4 vs CodeIgniter 3
| Area | CodeIgniter 3 | CodeIgniter 4 |
|---|---|---|
| Status | Legacy; mostly security updates | Actively developed |
| PHP version | Runs on very old PHP | PHP 8.1 or higher, 8.2 or higher for 4.7 |
| Namespaces and Composer | Limited | Built in |
| Structure | index.php in project root | index.php inside the public folder |
| Tooling | Basic | Spark CLI, migrations, testing helpers |
| Best for | Maintaining old projects | New projects |
If you maintain a CodeIgniter 3 app, plan a migration and learn the differences from our CodeIgniter 3 course and CodeIgniter 4 course.
Is CodeIgniter 4 still worth learning in 2026?
Yes, if your goal is fast, readable PHP projects, work in the many companies that still run CodeIgniter apps, or projects on modest hosting. If you want a large ecosystem of first-party packages and a bigger community, a larger framework such as Laravel may fit better. The choice depends on your project and team, not on a single winner.
Learn CodeIgniter 4 with Infovistar
- CodeIgniter 4 tutorial for beginners
- CodeIgniter 4 AJAX tutorial
- PHP tutorial
- JavaScript tutorial
- Practice with our online PHP compiler
FAQs
What is CodeIgniter 4 used for? It is used to build websites, admin panels, dashboards and REST APIs in PHP with the MVC pattern.
Which PHP version does CodeIgniter 4 need? CodeIgniter 4.7 requires PHP 8.2 or higher. The 4.6 line supports PHP 8.1, and 4.6.5 is the maintenance release for it.
Does CodeIgniter 4 use Twig? No. CodeIgniter 4 views are plain PHP files and it has a built-in View Parser. You can add Twig with a third-party package if you want it.
Is CodeIgniter 4 secure? It includes CSRF protection, output escaping, validation and a content security policy, and the team ships security patches. Your app is only as secure as your code and your update habit, so validate input and apply patches quickly.
How do I add login to CodeIgniter 4? Use Shield, the official authentication and authorization package, installed with Composer and set up with the spark shield:setup command.
Is CodeIgniter 4 faster than Laravel? CodeIgniter is lighter, so it often needs fewer resources, but real speed depends on your code, database and hosting. Test your own workload before deciding.
Should I migrate from CodeIgniter 3 to 4? Yes for any project you plan to keep. CodeIgniter 3 is in maintenance mode, and CodeIgniter 4 supports current PHP versions and active development. Plan the move in stages and test thoroughly.
Can I run CodeIgniter 4 on shared hosting? Yes, if the host offers a supported PHP version and lets you point the web root to the public folder.
Conclusion
CodeIgniter 4 stays a practical choice in 2026: small, fast to learn and actively updated. Use PHP 8.2 or higher with the 4.7 series, apply patches quickly, validate and escape everything, and use Shield for authentication. Start with the small posts example above, then follow our CodeIgniter 4 course to build a full application.
Version details were checked on October 28, 2026. Confirm the latest release and PHP requirements on the official CodeIgniter site before you follow any version-specific step.

