-
Notifications
You must be signed in to change notification settings - Fork 0
Better Server Setup for CI
This article describes how to setup a better, more secure CodeIgnitor folder structure on the server.
[h2]Explanation of this[/h2]
The default "officially documented" folder structure and setup for CodeIgnitor is pretty good for most situations, but I wanted to create a more secure, simple, and manageable folder structure where the bulk of code is not shared on the web (similar to Symfony or Zend).
Fortunately, this is easy to do with CI!
[h2]Benefits of doing this[/h2]
-
Separates your application folder from the CodeIgnitor core libraries folder
-
Places the bulk of your code outside of your public HTML folder, improving security.
-
Eliminates the need for those pesky security "index.html" files that clutter up the folder structure
-
Keeps database and other passwords off your website.
-
Makes upgrading to a newer version of CodeIgnitor dead simple.
-
Keeps you from being overly tempted to hack the CI core libraries when you really should be using plugins and hooks instead :)
[h2]How to do it[/h2]
Assuming that your home folder is named "homefolder", the basic CI installation on most web servers gives you this folder structure:
[code] homefolder public_html index.php system application cache codeignitor fonts etc... [/code]
What we want is this:
[code] homefolder app controllers models views libraries etc... ci cache codeignitor fonts etc... public_html index.php css etc... [/code]
The steps to set this up, from the default setup folder, are quite simple:
- Move the [i]system[/i] folder from the [i]public_html[/i] directory up one level to your home directory.
[code] ~# mv public_html/system . [/code]
- Move the [i]system/application[/i] folder up one level to your home directory.
[code] ~# mv system/application ./app [/code]
- Rename the [i]system[/i] folder to [i]ci[/i] (or whatever you want; something more descriptive is good)
[code] ~# mv system ci [/code]
- Edit the [i]index.php[/i] file in your public_html directory, and change the following lines:
From:
[code] $system_folder = "system"; [/code]
..to..
[code] $system_folder = "../ci"; [/code]
..and then change:
[code] $system_folder = "application"; [/code]
..to..
[code] $system_folder = "../app"; [/code]
And that's it!
[h2]Bonus[/h2]
Once you have this all setup (and if you are on an Apache Server), I recommend bringing the whole thing home by setting up an .htaccess file. The one I recommend is documented Dreamhost_.htaccess and works well on most all Apache servers.