0

CodeIgniter with Multiple Sites

Posted (Updated ) in PHP

CodeIgniter is an incredibly powerful and easy to use PHP Framework that makes developers’ lives alot easier. In its default configuration it only supports one site per installation – quickly result in thousands of files on your file server which can be a pain for all involved. With a little fiddling we can fix this. Here’s how:

Create a my_site and a globals folder in your web directory

Download the latest version of Codeigniter from here (I’m using 1.72) and unzip it to my_site. Your directory structure should look as follows

Default installation directory structure
Default installation directory structure

Move the system/application folder and place it next to the system folder. Move the system folder into globals/codeigniter and rename it to system_172. You can delete system/user_guide folder. We renamed system to system_172 so that if new versions of codeigniter are released, we can use this same method without affecting existing sites.

After moving system folder
After moving system folder

In your my_site folder, create a shortcut to the system folder you just moved and name it system

On Linux:
	ln -s ../globals/codeigniter/system_172/ system

Try loading your site. If it works – great! If not we’ll now need to edit my_site/application/index.php. I needed to make the following changes

At Line 26:
	$system_folder = "system";
Change to
	$system_folder = dirname(__FILE__)."/system";
 
At Line 43:
	$application_folder = "application";
Change to
	$application_folder = dirname(__FILE__)."/application";

You’re done! Load your site and enjoy your new streamlined installation.