How to Install Codeigniter 3 on Localhost

calendar_month 22 Jun 2020 | Codeigniter

CodeIgniter has an easy learning status compared to other frameworks and is the best PHP framework for beginners to develop dynamic websites with MVC (Model view controller) architecture, but can also code non-MVC applications. In this article, we will learn how to install CodeIgniter 3 on Localhost (Xampp Server).

There are the following steps to install CodeIgniter 3 on Localhost (Xampp Server)

Step 1: Download CodeIgniter

Download CodeIgniter 3 by clicking the following download link of the official CodeIgniter website.
Click on the link to download CodeIgniter 3:

Step 2: Extract Zip file

Extract the downloaded zip file and paste the extracted folder into the 'htdocs' directory, and rename the folder to your desired project name.

Step 3: Set Base Url

To set the base url, open the application/config/config.php file and set the base URL to http://localhost/type the CodeIgniter folder name here/

$config['base_url'] = 'http://localhost/type the CodeIgniter folder name here/';

Step 4: Autoload Libraries and Helpers

You can add helpers and libraries in the controller and model. But it is better to autoload some helpers and libraries. The database and the session are some of the key elements of almost all applications. So, we should add both libraries to the autoload file.
To autoload helpers and libraries, open the file application/config/autoload.php and make the following changes

$autoload['libraries'] = array('database', 'session');

Similarly, we use the base URL in the CodeIgniter app many times, so we need to load the URL helper into the autoload file.

$autoload['helper'] = array('url');

Step 5: Change default Controller

By default, the Welcome controller is set to default_controller, that's why the Welcome screen appears. You can set any controller to the default controller depending on your CodeIgniter application.

To change the default controller, open the application/config/routes.php file and make the following changes

$route['default_controller'] = 'welcome';

Step 6: Set Database credentials

Open the application/config/database.php file to configure the database credentials. $db['default'] is an array containing the database credentials, change the values of this array as follows.

$db['default'] = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'root', //write Database Username Here
	'password' => '', //write Database Password Here
	'database' => 'database_name', // write Database Name Here
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE

Step 7: Open the Project URL

To know that your CodeIgniter project is ready to run, simply load the following URL in a web browser to view the output of your application

http://localhost/type the CodeIgniter folder name here/
Ashwani Kumar

I'm a dedicated full-stack developer, entrepreneur, and proud owner of I reside in India, where I draw inspiration to create helpful tutorials and tips for fellow artisans. I'm deeply passionate about technologies like Bootstrap, PHP, CodeIgniter, Laravel, Node, React, JavaScript, and jQuery. I believe in working hard consistently, which keeps me motivated and driven. Challenges are opportunities to learn, setbacks are lessons. I find inspiration in the endless potential of technology and aim to make a meaningful impact with my work.

Buddy! I hope you relished the tutorial, and it was good to see you again. Keep learning. Keep visiting.

Related Tutorials
View all