Adam Kiss Posted January 11, 2011 Share Posted January 11, 2011 Hi Ryan, is it possible to hack something in PW, so it will work on two different servers? (staging AND live server) something like (pseudocode): $LIVE = (set_by_url) ? true : false; if($LIVE){ $db = 'hujul'; $db_user = 'user'; $db_pw = 'pw'; $db_server = 'this-one.com'; }else{ $db = 'staging-db'; $db_user = 'root'; $db_pw = 'root'; $db_server = 'staging.that-one.com'; } 2 Link to comment Share on other sites More sharing options...
ryan Posted January 11, 2011 Share Posted January 11, 2011 What you suggest should work just fine. Using your example, here's how I'd code it in your /site/config.php: Solution 1: <?php // If your dev/staging isn't 'localhost' then replace it with // whatever $_SERVER['HTTP_HOST'] is on your dev server: if($_SERVER['HTTP_HOST'] == 'localhost') { // staging or dev server $config->dbHost = 'localhost'; $config->dbName = 'pw2_blank'; $config->dbUser = 'root'; $config->dbPass = 'root'; $config->dbPort = '3306'; } else { // live server $config->dbHost = 'something'; $config->dbName = 'db_name'; $config->dbUser = 'db_user'; $config->dbPass = 'db_pass'; $config->dbPort = '3306'; } Solution 2: Another solution, and the one I use is to maintain a separate config file called /site/config-dev.php. ProcessWire looks for this file, and if it sees it, it'll use that rather than /site/config.php. If you just keep this file on your staging/dev server, and not on your live server, then that solves it for you. I also added that file to my .gitignore file so that it doesn't ever get deployed, while /site/config.php does. To get started with this method, just copy your /site/config.php to /site/config-dev.php (on your staging/dev server) and change the database settings in the config-dev.php version. 2 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 11, 2011 Author Share Posted January 11, 2011 This is wonderful information and I believe it fits into FAQ section (having just to have config-dev.php is nice, although I will probably prefer URL based decision–easier to maintain with good–ol' FTP / auto-sync editor (e.g. coda)) Adam Link to comment Share on other sites More sharing options...
diogo Posted January 21, 2013 Share Posted January 21, 2013 Bumping this very useful information. 1 Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 22, 2013 Author Share Posted January 22, 2013 Hah, thanks, I actually use it... a lot Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now