CodeIgniter 4 is a powerful PHP framework that’s perfect for building modern web applications. If you’re looking to get started with CodeIgniter, here’s a simple step-by-step guide to help you install it on your system.

Step 1: Check Your System Requirements

Before diving into the installation, make sure your system meets CodeIgniter’s requirements:

  • PHP version: 7.3 or higher (recommended is PHP 8.0+).

  • Extensions: Make sure you have extensions like intl, json, mbstring, and curl installed.

  • Composer (optional): Composer isn’t required, but it’s recommended for dependency management.

Step 2: Download CodeIgniter 4

You can install CodeIgniter 4 in two main ways: manually downloading it or using Composer. Here’s how to do both:

Option A: Manual Download

  1. Go to the CodeIgniter website and click on Download.

  2. You’ll get a ZIP file. Unzip it and move the contents to the desired directory for your project.

  3. Rename the folder if needed to something specific, like my_codeigniter_app.

Option B: Install Using Composer

Using Composer makes it easier to manage dependencies and keep your CodeIgniter version up-to-date:

  1. Open your terminal.

  2. Run the following command to create a new CodeIgniter project:

    composer create-project codeigniter4/appstarter my_codeigniter_app

    This will create a new folder named my_codeigniter_app with all the files needed for CodeIgniter 4.

Step 3: Set Up Your Base URL

  1. Open your project folder and locate the .env file. If you don’t see it, rename env to .env.

  2. Find the line starting with app.baseURL and set it to your project’s URL, for example:

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

Step 4: Configure Your Database (Optional)

If you want to connect to a database:

  1. In the .env file, look for the database section.

  2. Update the database settings to match your local setup:

    database.default.hostname = localhost
    database.default.database = your_database_name
    database.default.username = your_username
    database.default.password = your_password
    database.default.DBDriver = MySQLi

Step 5: Run the Development Server

Now you’re ready to run CodeIgniter!

  1. In your terminal, navigate to your project’s root directory:
    cd my_codeigniter_app
    
  2. Start the built-in development server with:
    php spark serve
    
  3. Open your browser and go to http://localhost:8080. You should see the CodeIgniter 4 welcome page!

Step 6: Explore the CodeIgniter Structure

Once you have CodeIgniter running, take some time to explore the folder structure. Here’s a quick overview:

  • app/Controllers: This is where you’ll define your application’s logic.

  • app/Models: Define your database interactions here.

  • app/Views: Store all your HTML files here.

  • public/: This folder holds assets and is the entry point for your app.

Wrapping Up

Congratulations! You’ve successfully installed CodeIgniter 4. Now, you’re ready to start building.