Using one Drupal settings file online and locally
Let's say you have this setup: You work on a site offline connected to a local mysql server (say MAMP), and you make a lot of changes and upload them online to the production site. The usual problem is that you have to avoid adding the settings.php file to your repository because if you deploy using something like Capistrano, you will have to change the database settings every time you deploy.
A simple solution is using $_SERVER[]
if ($_SERVER['SERVER_NAME'] === 'productionserver.com') $db_url = 'mysqli://username:password@onlineserver.com/production_database'; else $db_url = 'mysqli://root:root@localhost/local_database';
Pretty simple, right? Now it will load different databases depending on the environment (domain) you are working on. You can obviously play around with this.
latest posts
About
Hi, I'm Ivan Soto Fernandez (yes, two last names). I'm a chilean web developer living in Edmonton, Canada. I'm also an anime fan, Gundams lover and gamer. Welcome to my blog.
You can read more about me or follow me on Twitter or any of the following social websites.