Create a CodeIgniter application folder outside root on shared hosting

In this tutorial, we will see how to create a codeigniter application folder outside root level on server. Good thing with CI is that it is highly configurable and the application can be set up above the root level even on a shared hosting account e.g. Godaddy. All security experts advise to have the code hosted outside the root of your hosting to avoid your code being exposed to hackers in case of any security vulnerabilities or issues with your hosting server.

Ok, lets get started

  • First download the Codeigniter version you want to use from website : http://www.codeigniter.com/download
  • Let us assume that you want to serve your application from the folder root (e.g. \citest\root) which means your index.php file will be inside /root folder.
  • Now create another folder outside root folder. For this example , we have created a folder named aboveroot inside the same folder as root.
  • Below is how it will look inside citest folder where our root and aboveroot folders are located:
  • above root application directory
  • Now from the downloaded CI application copy the ‘application‘ and ‘system‘ folders inside the aboveroot directory. Below is how it should look:
  • above root application directory codeigniter
  • Now copy the index.php file in the root folder (and user_guide if you want the user guide available). Below is how it should look (files other than index.php are optional)
  • root directory with index.php file
  • Now the last and most important step. Open the index.php file and locate $system_path and $application_folder. Change them as below:
/*
 *---------------------------------------------------------------
 * SYSTEM FOLDER NAME
 *---------------------------------------------------------------
 */
	//Before 
        //$system_path = 'system';
	//After
        $system_path = '../aboveroot/system';

/*
 *---------------------------------------------------------------
 * APPLICATION FOLDER NAME
 *---------------------------------------------------------------
 * NO TRAILING SLASH!
 */
	//Before 
	//$application_folder = 'application';
	//After
	$application_folder = '../aboveroot/application';

 

If you are using a different folder or path,make sure the correct relative location for ‘application’ and ‘system’ folder is updated in the index.php file.

That’s all, browse the root folder now and you should be able to see your website.codeigniter home page

 


 

Updated: March 5, 2015 — 12:49 pm

Leave a Reply

Technology Central © 2014 - 2017 | Privacy Policy | Website Terms & Conditions