↓ Skip to main content

Setting up multiple applications with CodeIgniter

·2 mins

In ad­di­tion to my pre­vi­ous post where I dis­cussed the ini­tial setup of your ap­plic­a­tion with CI (CodeIgniter), I’ll use this post to provide a method of set­ting up your en­vir­on­ment for mul­tiple ap­plic­a­tions.

Now, in the pre­vi­ous post I was really sloppy about the loc­a­tions of both the CodeIgniter sys­tem files and the ap­plic­a­tion files. The same guidelines still ap­ply, both the sys­tem folder and ap­plic­a­tion folder should reside out­side of the web doc­u­ment root to en­sure safety.

First, we want to store our ap­plic­a­tions and CodeIgniter re­leases in sep­ar­ate folders. So for ex­ample store your CodeIgniter sys­tem folder in /var/codeigniter/. This could be done by do­ing a svn ex­port (or check­out) with the fol­low­ing command-line state­ment:

$ svn export http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/system/ /var/codeigniter/release-1.7.1

Or you can down­load the 1.7.1 re­lease from the CodeIgniter web­site and copy the con­tents of the sys­tem folder to /var/codeigniter/release-1.7.1.

Now for each ap­plic­a­tion you want to build you can do a export/checkout to our ap­plic­a­tions dir­ect­ory. As we are go­ing to store our ap­plic­a­tions out­side the doc­u­ment root you could pick /var/applications/ as root dir­ect­ory for your CI ap­plic­a­tions. Now if you want to make a blog you just have to ex­ecute this com­mand:

$ svn export http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/system/application/ /var/applications/blog[/bash] or [bash light="true"]$ cp /var/codeigniter/release-1.7.1/application /var/applications/blog

I prefer the SVN ex­port as this will en­sure that you al­ways have a fresh copy. Oth­er­wise, should you find your­self without an in­ter­net con­nec­tion you can use the lat­ter.

Now just as in the pre­vi­ous post, cre­ate the dir­ect­ory in the doc­u­ment root (whether you want to ac­cess it through a sub­folder or dir­ectly through a sub-domain/domain is en­tirely up to you and is out­side the scope of this post.)

$ mkdir /var/www/blog

Now get the index.php file from svn or from the zip file you might have down­loaded earlier:

svn export http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/index.php /var/applications/blog/

The only thing left is to al­ter the index.php so the $system_folder and the $application_folder point in the right dir­ec­tion:

//...
$system_folder = '/var/codeigniter/release-1.7.1';
//...
$application_folder = '/var/applications/blog';

Now you can add your web stuff like CSS, JS to your /var/www/blog. Of course this fol­lows the same prin­ciple as cre­at­ing the non-www and www dir­ect­or­ies men­tioned in the pre­vi­ous post.

Now for each ap­plic­a­tion you want to add, re­take the above steps and re­place ‘blog’ with some­thing rel­ev­ant. Good steam­ing!