CodeIgniter 4 is a modern PHP framework that can be installed using various methods. This tutorial will guide you through the most common installation approaches, running your application, and ensuring your server meets the requirements.
Prerequisites
Before installing CodeIgniter 4, ensure your server meets the following requirements:
- PHP Version: PHP 7.4 or newer (preferably PHP 8.0+).
- Extensions Required:
intl
,mbstring
, andcurl
. - Web Server: Apache, Nginx, or any web server that supports PHP.
Installation Methods
CodeIgniter 4 can be installed using three primary methods:
- Manual Installation
- Composer Installation
- Git Installation
Composer Installation
Composer is the recommended way to install CodeIgniter 4 as it allows you to manage dependencies and easily update your project.
Steps for Composer Installation:
Install Composer:
- If Composer is not installed on your system, download and install it from getcomposer.org.
Install CodeIgniter 4 Using Composer:
- Open your terminal and run the following command to create a new CodeIgniter 4 project:
composer create-project codeigniter4/appstarter your-project-name
- Replace
your-project-name
with your desired project folder name.
Navigate to Your Project Directory:
- Change into your project directory using:
cd your-project-name
Set Up Your Application:
- Configure your environment settings by renaming the
env
file to.env
and adjusting settings like database credentials and base URL. php spark serve
- This command will start the server on
localhost
at port8080
by default. http://localhost:8080/
- Configure your environment settings by renaming the
Welcome Page:
- You should see the default CodeIgniter 4 welcome page, confirming that the installation was successful.
Troubleshooting
- PHP Extensions Not Installed: If you encounter errors regarding missing extensions (
intl
,mbstring
,curl
), ensure they are enabled in yourphp.ini
configuration file. - Port Already in Use: If port
8080
is already in use, you can specify a different port when running the server: php spark serve --port=8081
Note
Before using CodeIgniter 4, make sure that your server meets the requirements.