How to install Codeigniter in Xampp

Codeigniter is one of the most popular and lightweight PHP framework till date. Codeigniter is based on MVC design pattern and it requires almost zero configuration. In this tutorial I am going to download and install codeigniter in xampp.

Also Read:

Step 1: Download Codeigniter

Download Codeigniter from its official site ( Right now there are two version of codeigniter (3.x, 2.x) on download page. I personally recommend to download Codeigniter 3.x version. Because 3.x version, there have been a number of refinements since 2.x version.

codeigniter versions

Step 2: Extract Codeigniter Files

Extract downloaded zip folder into the xampp/htdocs folder.

codeigniter folder htdocs

Rename folder according to your project name. I am going to change folder name with demo

Step 3: Set Base Url

Open config.php file located in application/config folder and set value of $config['base_url']. In our example base url will be http://localhost/demo/

Step 4: Test Localhost Url

Go to your browser and hit localhost/demo. You will see below screen.

localhost demo codeigniter

Step 5: Change default Controller in Routes

Change default controller in application/config/routes.php. By default welcome controller is set in default_controller that’s why you get welcome screen. You can set any controller to default controller depends on your codeigniter application. If you will be creating blog or website then default controller must be one which redirects user to home page. If you are creating an application in which user have to sign in first then your default controller must be login controller. In routes.php you can also define URL routes. For more details you can visit URI Routing page of codeigniter documentation.

Step 6: Add database Credentials

Add database credentials in application/config/database.php file. $db['default'] is an array holding database credentials.

Step 6: Auto load Helpers and Libraries

I can add helpers and libraries in controller and model. But it is better to auto load some helpers and libraries which I am going to use throughout my application. Database and Session are one of the key elements of almost every application. So I am going to add both of these libraries in my application/config/autoload.php file.

At some point I need to get the URL either to add active or inactive CSS class in my application nav menu or just to verify in what controller and function I am standing in. Codeigniter URL helper will do that for me so I will also auto load this helper.


Leave a Reply

Your email address will not be published. Required fields are marked *