I am using shared hosing for Codeigniter application for deployment. How can i run staging url on live server?

1) domain.com (Working) 2) domain.com/staging/ (Not working, showing 404 error)

I created staging folder under public_html directory, now put All CI code in staging folder, and tried to run the application with URL domain.com/staging/ but it redirect on domain.com/404

I expect to run domain.com for users and domain.com/staging for development. (Staging URL i will use for development and after that i will place the same code for live URL.)

1 Answers

DFriend On

This is most easily done by using a subdomain for the staging version, i.e. staging.doman.com. The folder where you put the CI files isn't super important as the subdomain will be set to use the directory you choose.

You will either need to have complete control over the server or have a service provider that allows you to set up subdomains.

- Expanded Answer -

If you cannot set up a subdomain then your next best option is to use the advice in the documentation on Managing you Applications. It isn't required to use the file structure shown there. In your case try the following.

  1. Create a folder on the same level as application named staging.

  2. Into that folder copy all the folders and files normally found in /application.

Add all application folders and files required by your site. The files in these folders are those that make up the application you are staging.

  1. Make a copy of index.php (the file at the root of the public folder, i.e. domain.com/index.php) and name it staging.php. Both index.php and staging.php will be in the same folder.

  2. Edit staging.php and change the value of $application_folder to be the absolute path to the staging folder. For example:

    $application_folder = '/path/to/domain.com/public_folder/staging';

The path above is an example. You must replace it with the actual path in your server. If you have no idea what the full and absolute path is you can use

$application_folder = dirname(__FILE__).'/staging';
  1. Browse to the URL domain.com/staging.php and you should get your default controller's output. To test that you are actually seeing the staging version of the page temporarily change something in the view file so there can be no doubt.

You will go to other controllers by using the URL domain.com/staging.php/other_controller.

  1. Change the value of $config['index_page'] in /staging/config/config.php to staging.php, e.g.

    $config['index_page'] = 'staging.php';

Without the above change redirect() and many other "helper" functions will not work correctly.

  1. (Optional?) You can probably edit the main .htaccess and add rewrite rules for staging.php the same way it is done for index.php. But I will leave that as an exercise for you. (Or for another SO question.)

A final word. It might be necessary to make other configuration changes to accommodate the revised file structure. I tested the answer here but did not go beyond the most basic task of browsing to controllers. Most likely config values for sessions, cookies, and many others will need to be adjusted for the staged version to work correctly. Check out the documentation on Handling Multiple Environments for guidance on making this less painful.