Installing CodeIgniter – Step by step guide

Below is a minimal step by step guide on installing CodeIgniter 2.1.4. The assumptions are that your using either Ubuntu or Debian, with a GIT + Apache + PHP + MySQL stack available.

Step 1: Clone the CodeIgniter repository

CodeIgniter is available either as a compressed tarball, or as a git repository. The latter is a straightforward way of downloading, installing and maintaining an up-to-date version of CI, enabling you to switch to experimental branches at any given time. Clone the repository:

git clone .

Step 2: Change folder permissions

Give permissions to your Apache user (default www-data) and group (similarly, www-data):

chown -R www-data:www-data /path/to/ci

Step 3: Configure your Apache VirtualHost

Next step is to configure you Apache's VirtualHost DocumentRoot to point to the cloned folder, with enabled .htaccess.

sudo vi /etc/apache2/sites-enabled/your-site-name.tld

Adjust the template below accordingly:

<VirtualHost *:80>
        DocumentRoot /path/to/ci
        ServerName your-site-name.tld
        ServerAlias *.your-site-name.tld
        <Directory "/path/to/ci/">
                Options -Indexes -MultiViews FollowSymLinks
                AllowOverride All
                Order allow,deny
                allow from all

	CustomLog ${APACHE_LOG_DIR}/your-site-name.tld-access.log combined
	ErrorLog ${APACHE_LOG_DIR}/your-site-name.tld-error.log

Step 4: Create an .htaccess file, in your DocumentRoot path, to avoid including the index.php in your URLs

vi /path/to/ci/.htaccess

Add the following lines (taken from here):

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Step 5: Once the file is saved, reload Apache

sudo apache2ctl reload

Step 6: Load your page, and add a fist view

Loading your CI instance for the first time, will display a Welcome page. You can use the controller found in application/controllers/Welcome.php as a base template for your new controllers. Feel free to remove this file, once you do not need it, along with the sample application/controllers/welcome_message.php file.

NOTE: Controller file and class names must be capitalized.

Below is an example Hello World controller stored in application/controllers/Home.php:

defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {
        public function index()
                echo "Hello World.";

Step 7: Read more about configuration and folder structure in my next posts.

Leave a Reply

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