Setting up multiple applications with CodeIgniter

Sep 8, 2009 00:00 · 381 words · 2 minutes read mvc codeigniter partials partial rss

In addition to my previous post where I discussed the initial setup of your application with CI (CodeIgniter), I’ll use this post to provide a method of setting up your environment for multiple applications. Now, in the previous post I was really sloppy about the locations of both the CodeIgniter system files and the application files. The same guidelines still apply, both the system folder and application folder should reside outside of the web document root to ensure safety.

First, we want to store our applications and CodeIgniter releases in separate folders. So for example store your CodeIgniter system folder in /var/codeigniter/. This could be done by doing a svn export (or checkout) with the following command-line statement:

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

Or you can download the 1.7.1 release from the CodeIgniter website and copy the contents of the system folder to /var/codeigniter/release-1.7.1.

Now for each application you want to build you can do a export/checkout to our applications directory. As we are going to store our applications outside the document root you could pick /var/applications/ as root directory for your CI applications. Now if you want to make a blog you just have to execute this command:

$ 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 export as this will ensure that you always have a fresh copy. Otherwise, should you find yourself without an internet connection you can use the latter.

Now just as in the previous post, create the directory in the document root (whether you want to access it through a subfolder or directly through a sub-domain/domain is entirely up to you and is outside 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 downloaded earlier:

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

The only thing left is to alter the index.php so the $system_folder and the $application_folder point in the right direction:

//...
$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 follows the same principle as creating the non-www and www directories mentioned in the previous post.

Now for each application you want to add, retake the above steps and replace ‘blog’ with something relevant. Good steaming!