-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Better Server Setup for CI
This article describes how to setup a better, more secure CodeIgniter folder structure on the server.
The default "officially documented" folder structure and setup for CodeIgniter 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!
-
Separates your application folder from the CodeIgniter 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 CodeIgniter dead simple.
-
Keeps you from being overly tempted to hack the CI core libraries when you really should be using plugins and hooks instead :)
Assuming that your home folder is named "homefolder", the basic CI installation on most web servers gives you this folder structure:
homefolder
public_html
index.php
system
application
cache
codeigniter
fonts
etc...
What we want is this:
homefolder
app
controllers
models
views
libraries
etc...
ci
cache
codeigniter
fonts
etc...
public_html
index.php
css
etc...
The steps to set this up, from the default setup folder, are quite simple:
- Move the system folder from the public_html directory up one level to your home directory.
~# mv public_html/system .
- Move the system/application folder up one level to your home directory.
~# mv public_html/application ./app
- Rename the system folder to ci (or whatever you want; something more descriptive is good)
~# mv system ci
- Edit the index.php file in your public_html directory, and change the following lines:
From:
$system_folder = "system";
..to..
$system_folder = "../ci";
..and then change:
$application_folder = "application";
..to..
$application_folder = "../app";
And that's it!
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.