Why do I need a development version?
Website development never stops when the site is finally launched. It is a constant struggle to innovate. Eventually, after launching you will have visitors. Now, if you have visitors, you need to find a way to develop on your site without showing it to your visitors. Sure, you can develop offline. But, before making it live, you still need to test if it works on live right? That’s why you need to have a development version to your site
What big companies do?
If you are a big company like Facebook that has a lot of money to spend on servers, you can simply set up a test server. But this won’t work if you are a small time web entrepreneur.
How to add a development version to a Codeigniter site?
For codeigniter, there is a way to add a development version to your site without using too much resources like disk space. Here are the steps.
Create multiple applications
The main trick here is to create multiple applications in a single Codeigniter installation. These applications will be your live and dev sites. You simply create 2 new directories under the application directory mainly “dev” and “live”. Then copy all the contents of application into dev and live. If you have cPanel you can use Filemanager to do this.
Create dev subdomain
What we are going to do here is we want our development site to be accessible via dev.example.com and our live site to be accessible via www.example.com. Here is what we are going to do. We need to create a subdomain called dev and make it point to the root.
Final Step
Now that we’ve created the subdomain. The only thing left to do is make the “dev” point to the development version and the “www” to the live version. All you need to do is go to Codeigniter’s index.php and find “APPLICATION FOLDER NAME” then you need to replace the code as per below.
/* *--------------------------------------------------------------- * APPLICATION FOLDER NAME *--------------------------------------------------------------- * * If you want this front controller to use a different "application" * folder then the default one you can set its name here. The folder * can also be renamed or relocated anywhere on your server. If * you do, use a full server path. For more info please see the user guide: * http://codeigniter.com/user_guide/general/managing_apps.html * * NO TRAILING SLASH! * */ if($_SERVER['HTTP_HOST']=='dev.example.com'){ $application_folder = 'application/dev'; }else{ $application_folder = 'application/live'; } |
And that’s it. So when you need to edit the code you can first edit the dev. If you are happy with the code then you just copy (Ctrl+drag) the contents of dev into live using Filemanager to deploy it.
I hope this tutorial is of any help. Cheers!