I needed to do an update to the Drupal installation for my website today and my preferred way of working is to do the update locally and then ftp the new files up to my production server and run the database update (after backing everything up of course). When I went to do this today I realized that after moving to a new laptop last week I forgot to move the configuration files for my local WAMP server and I didn’t have them backed up (bad developer). Since I had already cleaned my old hard drive I needed to recreate my local configuration and I figured this time I would document it. This is mainly for my benefit but if someone else finds this useful that would be great.
In a basic Drupal installation there is a ‘default’ site defined but you have the option of defining as many sites as you want, each with their own settings file. Drupal maps domains to a ‘site’ folder so to create a separate ‘site' for http://www.andrewalderson.com I created a folder called ‘andrewalderson.com’. This folder contains the settings file that defines things like the database connection string for that site. This is great for my production website but what about running a dev enviroment on my local machine. I could just define the dev settings in the ‘default’ site settings but a better solution is to define a site for the local dev environment. In my case I created a site called andrewalderson.local (you can use whatever domain you like here). I set up this site on my local WAMP server and it is viewable at http://andrewalderson.local. The settings file for this site contains the database connection string for the local copy of the database.
To set up a site like this on your local machine you need to do 2 things. First you need to edit your hosts file to redirect this url. In my hosts file (on a Windows system found in c:\Windows\System32\drivers\etc) I added the line:
127.0.0.1 andrewalderson.local
This redirects any requests for andrewalderson.local to 127.0.0.1 (which is where my Apache server is running).
The second thing we need to do is add a virtual host to Apache to redirect this request to the correct directory. This is done different ways depending on your Apache install but for a standard WAMP install you can create a new file in the ‘alias’ directory in the WAMP server root. I created a file called ‘andrewalderson.conf’ with the following content:
<VirtualHost andrewalderson.local>
DocumentRoot "C:/path/to/your/drupal/install/"
ServerName andrewalderson.local
<Directory "C:/path/to/your/drupal/install/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
</VirtualHost>
I keep my website files in my Documents folder instead of the root of the WAMP server. So the directory path would be the file system path to the ‘drupal’ folder (including the ‘drupal’ folder)
Lastly I just restart WAMP and browse to http://andrewalderson.local to view my local site. Now I can make updates to my website locally and upload those changes without having to edit configuration files. When I am working locally the settings for the andrewalderson.local site are used and on production the settings for the andrewalderson.com site are used.
Add new comment