![]() |
Configure CodeIgniter to run on two servers - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Configure CodeIgniter to run on two servers (/showthread.php?tid=19296) Pages:
1
2
|
Configure CodeIgniter to run on two servers - El Forum - 06-03-2009 [eluser]neillyons.co[/eluser] Using a dynamicly defined constant in the index.php file, CodeIgniter can be set up to run on two servers. I have found this really speeds up my development time, especially if used along with Bazaar Upload for Web ( http://bazaar-vcs.org/BazaarUploadForWebDev ). With this feature, the same CodeIgniter installation can run on two servers without the need to change variables. Step 1 To implement this feature into CodeIgniter, edit the index.php file, and include the following code at the top. Code: if ($_SERVER['SERVER_NAME'] == 'localhost') Step 2 Alter the “config.php” file ( ../application/config/config.php ), by replacing the original “base_url” variable, with the code below. Code: if (SITE_LIVE) Step 3 Alter the “database.php” file ( ../application/config/database.php ), by replacing the original variable with the code below. Code: if (SITE_LIVE) Configure CodeIgniter to run on two servers - El Forum - 06-04-2009 [eluser]bmchild[/eluser] Looks like a good idea to switch between dev and production versions. I like it. I've also done something similar to choose between application folders depending on which host is being called, although I don't think I would do that for a site that is very complicated. Configure CodeIgniter to run on two servers - El Forum - 06-04-2009 [eluser]Fatih[/eluser] Good feature. Maybe you can use below codes in your database.php file for clear coding. Code: if (SITE_LIVE) Also, if you can use cookies to get user information, your visitors shall be login in every changed servers. Configure CodeIgniter to run on two servers - El Forum - 06-05-2009 [eluser]eoinmcg[/eluser] I do something very similar, switching between my local machine and production server. In config/config.php Code: $config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/"; Then in config/database.php Code: if ($_SERVER["SERVER_ADDR"] != '127.0.0.1') Configure CodeIgniter to run on two servers - El Forum - 06-05-2009 [eluser]neillyons.co[/eluser] @fatigue. I was looking through DB.php ( ../system/database/DB.php ) and noticed that CodeIgniter does already allow multiple database settings. Code: $params = $db[$active_group]; To set which settings just define $active_group like you said. Kudos fatigue, I didn't pay any attention to the $active_group variable before. I think using CodeIgniter's ( and your ) implementation is best. Configure CodeIgniter to run on two servers - El Forum - 06-05-2009 [eluser]eoinmcg[/eluser] Must admit that, I too, hadn't paid attention to using Code: $active_group Nice tip, cheers! ![]() Configure CodeIgniter to run on two servers - El Forum - 06-05-2009 [eluser]Phil Sturgeon[/eluser] Here's my views on this one "How to Support multiple production environments in CodeIgniter". Using that approach cleans up your config files from storing domains in multiple locations and allows you to have a database file such as: Code: // Local Configure CodeIgniter to run on two servers - El Forum - 07-01-2009 [eluser]neillyons.co[/eluser] After looking through the CodeIgniter.php file ( ../system/codeigniter/CodeIgniter.php ) I noticed that constants are loaded on line 52. Code: require(APPPATH.'config/constants'.EXT); I recommend removing the constant SITE_LIVE I defined in the index.php to the constants.php file ( ../system/application/config/constants.php ). To make upgrading the core easier. Configure CodeIgniter to run on two servers - El Forum - 07-01-2009 [eluser]TWP Marketing[/eluser] Between my dev and live servers the only change I need to make is in (under WIN XP) the hosts file. I uncomment (dev) or comment (live) the declaration of my site url in hosts. For example: Code: in hosts file The # is the comment delimiter. I realize this is windows centric but it is far simpler than the code mods discussed above. I regret that I don't know if something similar is available under other OS's, but if you run under win, it works well and is quick. No guarantee that this works if you are using Vista... Caveate: it requires that your local httpd.conf file contain virtual host definitions matching the live site installation. Use the same ServerName as in the hosts file, but this is simple to arrange. For example: Code: in httpd.conf file The DocumentRoot param points to where your code resides on both the dev and live sites. IT DOES NOT NEED TO BE THE SAME AS SERVERNAME. If you can't control where the live site is installed, change your dev configuration to match the live site. This is a one-time-only change at the time of project setup. Configure CodeIgniter to run on two servers - El Forum - 07-01-2009 [eluser]neillyons.co[/eluser] I guess my solution is most useful if you use http://bazaar-vcs.org/BazaarUploadForWebDev which only uploads the files that have changed on your development site to the live site. This solution allows no changes to be made to the code after it's been initially configured. |