↓ Skip to main content

Setting up CodeIgniter - Basics

·2 mins

In this post I’ll show how to set up CodeIgniter in a way that your code and con­fig­ur­a­tion (pass­words!) are safe. It will in­volve mov­ing the “sys­tem” and “ap­plic­a­tion” out­side the (pub­lic) doc­u­ment root.

Seper­at­ing both <em>system</em>' and ap­plic­a­tion’ has ob­vi­ous ad­vant­ages for main­tain­ance and for re­usib­il­ity. Us­ing a seper­ate `www’ dir­ect­ory en­ables you to pub­lish all your ap­plic­a­tion spe­cific JS/CSS and other pub­lic files.

The first thing we need to do is to cre­ate an check­out of the latest CodeIgniter re­lease (cur­rently 1.7.1)

$ svn checkout http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/ somepathoutsidedocumentroot

now move the ap­plic­a­tion folder out­side the sys­tem folder:

$ cd  somepathoutsidedocumentroot
$ mv system/application ./application

Now move the sys­tem and ap­plic­a­tion folder to some folder out­side of your pub­lic doc­u­ment root. Let’s call this dir­ect­ory <em>non-www</em>'. The documentroot directory will be called www'.

In the root of your check­out you will find an index.php. Copy/move this file to www. Open it and look for the fol­low­ing lines:

$system_folder = "system";
$application_folder = "application";

Change them to the fol­low­ing:

$system_folder = "../non-www/system";
$application  = "../non-www/application";

Now you are up and run­ning. Prob­ably you want some­thing like nice url’s. For this you can use the fol­low­ing .htac­cess

RewriteEngine on
RewriteRule ([^/]*)\/\?([^/?]*)$ $1/$2 [R]
RewriteCond $1 !^(index\.php|test\.php|export\.php|robots\.txt|css|img|js|favicon\.ico|doc|data|user_guide|js)
RewriteRule ^(.*)$ ./index.php/$1 [L]

Now, go and cre­ate some new shiny sites.