How to Download & Install CodeIgniter with Composer

โšก Smart Summary

Installing CodeIgniter can be done two ways: downloading the framework zip from the official site, or letting Composer automate it. After installation, the config files set the base URL, class prefix, and query strings, and an .htaccess rule removes index.php from URLs.

  • ๐Ÿ“ฅ Two Methods: Download the zip and unzip it, or run a Composer command to install and update automatically.
  • ๐Ÿ–ฅ๏ธ Quick Test: The built-in PHP server confirms the install runs before further setup.
  • ๐Ÿ“ฆ Composer: A PHP package manager that pulls CodeIgniter from the Packagist repository.
  • ๐Ÿ—‚๏ธ Config Files: autoload, config, database, routes, and more control application behaviour.
  • ๐ŸŒ Base URL: Set base_url in config.php, or leave it blank for CodeIgniter to detect it.
  • ๐Ÿท๏ธ Class Prefix: A custom prefix like MY_ avoids collisions with internal CI_ classes.
  • ๐Ÿ”— Clean URLs: Blanking index_page and adding an .htaccess rewrite removes index.php from the URL.

CodeIgniter Install with Composer

In this tutorial, we look at how you can install and configure CodeIgniter. There are two ways to install CodeIgniter. You can download the latest version from the CodeIgniter website, or you can use a tool like Composer to automate the installation.

How to Download and Install the CodeIgniter Framework

The source code for the CodeIgniter framework is available on the official CodeIgniter website. If you want to download the latest version of the framework, you should do it from the official web page.

Step 1) Download the CodeIgniter framework. Open the following URL in your browser: https://codeigniter.com/. The image below shows the download link to the latest version of the framework.

Download CodeIgniter framework

Step 2) Unzip the CodeIgniter-4.1.4.zip file. Clicking the link above downloads the framework as a zipped folder. Unzip the contents of CodeIgniter-4.1.4.zip.

Step 3) Create a new directory. Suppose you want to create a project called the online store. Create a new directory on your development drive, for example D:\Sites\online-store.

Step 4) Open the contents of CodeIgniter-4.1.4. You should now see the following files. Copy the contents to your project directory, for example D:\Sites\online-store.

CodeIgniter files copied to the project directory

Step 5) Open the terminal and run the following commands. Change into the project directory:

cd D:\Sites\online-store

Then start the built-in PHP server, just to make sure everything is OK:

php -S localhost:3000

Step 6) Open the URL. Load the following URL into your browser: http://localhost:3000/

CodeIgniter welcome page in the browser

If you see the image above, all is working well.

What is Composer in CodeIgniter?

Composer in CodeIgniter is a package management system for PHP. A package is simply a collection of PHP scripts that work together toward a single goal. Based on this definition, CodeIgniter, even though it is a framework, qualifies as a package in Composer terminology.

The following image shows how Composer works in CodeIgniter:

Composer in CodeIgniter
Composer in CodeIgniter

The author of CodeIgniter hosts the package at Packagist, which is a central repository for PHP packages.

When the developer runs the Composer command to download CodeIgniter, Composer communicates with Packagist and downloads the latest release of the package. In addition to installing frameworks such as CodeIgniter, Composer can also be used to:

  • Install individual packages, such as a third-party email or database library.
  • Update existing packages.
  • Remove installed packages.

How to Download and Install Composer

Here are the steps to download and install Composer in CodeIgniter:

Step 1) Load the following URL in your browser: https://getcomposer.org/download/. Download the setup and follow the installation instructions.

Step 2) Open the command prompt or terminal and run the following command:

composer

You will see the following results:

Composer installed successfully

If you can see the results above, congratulations, you have successfully installed Composer. Now let us create a new project called online-store. Run the following command:

composer create-project CodeIgniter/framework online-store

Here:

  • composer create-project CodeIgniter/framework online-store: composer invokes the Composer program, and create-project downloads the specified project framework, which is in the namespace CodeIgniter.

You should see results similar to the following:

Composer creating a new CodeIgniter project

If you are a fan of terminal commands, this is the way to go. Otherwise, you can use the good old-fashioned approach: download the zipped file, unzip it, and start coding.

CodeIgniter Config Files

Now that we have successfully installed CodeIgniter, let us look at the configuration directory. The configuration directory is located in:

application/config

CodeIgniter config directory

Here:

  • autoload.php โ€“ specifies the helpers, libraries, drivers, and packages that should be loaded when the application starts.
  • config.php โ€“ contains application configurations such as base URL, language, and query strings.
  • constants.php โ€“ as the name suggests, this file is used to define application constants.
  • database.php โ€“ contains database connection parameters.
  • doctypes.php โ€“ defines document types, i.e. html4, html5, and so on.
  • foreign_chars.php โ€“ defines foreign characters, that is, characters found in languages such as Russian and others.
  • hooks.php โ€“ allows you to define your own hooks.
  • memcached.php โ€“ if you are using CodeIgniter together with Memcached, you can use this file for configuration.
  • migration.php โ€“ if you want to use database migrations in CodeIgniter, you can use this file to configure the settings.
  • mimes.php โ€“ contains file mime types.
  • profile.php โ€“ contains settings used by the built-in CodeIgniter compiler.
  • routes.php โ€“ contains the application routes.
  • smileys.php โ€“ contains settings for smileys.
  • user_agents.php โ€“ contains settings for browser user agents, i.e. Chrome, Opera, Firefox, and so on.

CodeIgniter Configurations

Let us now make some of the most common settings in CodeIgniter. Open application/config/config.php.

Base URL

$config['base_url'] = '';

This sets the base URL. If it is blank, CodeIgniter sets it for you automatically. If you want to be explicit about your base URL, you can use something like the following:

$config['base_url'] = 'http://localhost:3000';

Here:

  • $config[‘base_url’] = ‘http://localhost:3000’; sets the base URL to localhost running on port 3000.

Class Prefix

CodeIgniter uses the prefix CI_Classname. As a best practice, and to avoid collisions with internal classes, you can prefix your own class, i.e. MY_Classname. The following line sets your class prefix:

$config['subclass_prefix'] = 'MY_';

Query Strings

These are parameters that are visible in the URL, i.e. example.com/index.php?q=eggs. If you would like to use such URLs, you have to set:

$config['enable_query_strings'] = FALSE;
To
$config['enable_query_strings'] = TRUE;

Other Settings

There are many settings you can configure in config.php, including date formats, cache, and view paths. Much of what you configure depends on your application needs.

How to Remove index.php in CodeIgniter

CodeIgniter is an MVC framework. This means it has a single entry point into the application, which is index.php. It does not matter what URL you access; they all go through index.php. By default, index.php is shown in the URL, as in the example below:

example.com/index.php?q=eggs

The URL looks longer and odd. The good thing is you can configure CodeIgniter to remove that. Open application/config/config.php and locate the following line:

$config['index_page'] = 'index.php';
Set it to the following
$config['index_page'] = '';

Here:

  • We are using mod_rewrite to remove the page, so as per requirement this should be set to blank.

Next, we need to create the .htaccess file that rewrites the URLs. Add a new file .htaccess in the root directory of the application and add the following code:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Here:

  • The code above is for configuring web servers that run the Apache server. It basically takes the URI parameters and executes them via index.php, even when index.php is not shown in the browser URL.

FAQs

Use the zip download for a quick one-off install. Use Composer when you want dependency management and easy updates, which is the better choice for a maintained project.

No. The built-in PHP server started with php -S localhost:3000 is enough to test locally. For production you still need Apache or Nginx with the correct rewrite rules.

Cleaner URLs are easier to read and better for SEO. Blanking index_page and adding an .htaccess rewrite hides the entry file while still routing every request through it.

Yes. AI can generate the base_url, database, and routing config from a description, and write the .htaccess rewrite. Confirm the paths against your framework version, since CodeIgniter 4 restructured directories.

CodeIgniter’s own classes use the CI_ prefix. Giving your extensions a distinct prefix such as MY_ prevents name collisions with core classes and makes it clear which code is yours.

Summarize this post with: