Installing CodeIgniter
CodeIgniter 4 is distributed as a Composer project. Before starting, confirm that PHP 8.1 or newer is available and that the intl, mbstring, and json extensions are enabled.
Create the project
composer create-project codeigniter4/appstarter ci-app
cd ci-app
php spark serve
The development server listens on port 8080 by default. Open http://localhost:8080 and the CodeIgniter welcome page should appear.
Configure the environment
cp env .env
CI_ENVIRONMENT = development
app.baseURL = 'http://localhost:8080/'
In development you get detailed error pages and the debug toolbar. Switch to production only on the live server.
Connect a database
database.default.hostname = localhost
database.default.database = ci_app
database.default.username = app_user
database.default.password = secret
database.default.DBDriver = MySQLi
Keeping credentials in .env means the same codebase can run on a laptop, a staging server, and production.
Folder permissions
The writable directory must be writable by the web server. On Linux, use group ownership rather than permissive 777 permissions. On Windows, the default permissions normally work.
Useful spark commands
php spark routes
php spark make:controller Catalog
php spark make:model ProductModel
php spark make:migration CreateProducts
php spark migrate
If the page loads without styles, check that app.baseURL matches the address in your browser, including the trailing slash.