This tutorial will explain how to install CodeIgniter using the command line and demonstrate the steps involved in setting up your website.

The main benefit to using the command line to install CodeIgniter is the quick and easy file download from the CodeIgniter website to your server.

Alternatively, you may download the CodeIgniter files and use an FTP client to upload them, however, that method is not the preferred way of sourcing the files because it takes longer.

Tutorial Information

Installation Difficulty: Beginner

Installation Time: 10 Minutes

How to install CodeIgniter using the Command Line

Firstly, login to your server using your command line client, and navigate to your websites folder.

cd /var/www/html

Secondly, download the CodeIgniter files using wget.

wget https://github.com/bcit-ci/CodeIgniter/archive/3.1.10.zip

We now need to unzip the archive which we have just downloaded.

unzip 3.1.10.zip

Next, move the CodeIgniter files out of the directory which was automatically created and into the root folder of our website.

mv CodeIgniter-3.1.10/* .

Finally, remove the empty CodeIgniter directory.

rm CodeIgniter-3.1.10/

Now that you have CodeIgniter downloaded onto your website and extracted, all that is left to do is configure it to connect to our database.

How to configure CodeIgniter

Open the database.php file located in root-folder/application/config

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'my_user';
$db['default']['password'] = 'my_password'; 
$db['default']['database'] = 'my_database';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


/* End of file database.php */
/* Location: ./application/config/database.php */

In here you will find the preset variables already written out, however, we still need to fill in the blanks and insert our mysql information.

See the code snippet above for an example of how to do this.

The majority of your CodeIgniter project will be written in files contained within the application directory.

The main files and folders you will need are:

  • application/config/routes.php
  • application/controllers/
  • application/views/
  • application/models

Defining a route in the routes configuration file will load a controller. From your controller, you may call models to perform database functions and views to display pages to your viewers.

Conclusion

That’s it! CodeIgniter is now installed and configured, ready for your next project.

To get started, check out our CodeIgniter tutorials and leave a comment if there is anything you would like to see in this section.