Live Drupal site to a Wampserver development environment

Chris Graham's picture

The Problem

We were recently asked by a member of staff to give them access to one of our websites on a laptop so that they could demo it at a meeting.

The Solution

I decided to go with Wampserver and a local copy of the site as the demo did not need to have the latest content.

The site in question was a part of a Drupal multisite install, this complicated matters given that the site was also using files from other sites.  In order to speed up the process I decided to copy the entire Drupal install across (we'll probably use the other sites to demo at some point anyway).

The following is the breakdown of what I did to get everything up and running.

Installation

  • Download Wampserver 2.0h from Sourceforge (latest version includes PHP 5.3.0 which is incompatible with Drupal 6)
  • Install Wampserver under an administrator account and set the wampapache and wampmysqld services to automatically run from the services management (Start > Run > services.msc)
  • Add the rewrite module for Apache using the Wampserver console (Wampserver > Apache > Apache modules)
  • Create a local database for the site and import the structure and data from the live site (I use SQLYog as it is free (Community Edition), fast and keeps the Drupal anonymous user id at zero, PHPMyAdmin sets this to an auto-increment value).  If there are issues with the import and you are getting "Error code 2006: MySQL server has gone away" when using SQLYog then you need to configure your mysql.ini file (see Configuration below).
  • Copy live Drupal site files to C:/wamp/www

Configuration

mysql.ini

SQLYog doesn't allow Gzip exports so I had to increase the max_allowed_packet setting to allow imports to the local database as the uncompressed database export was 8M.  I set it to 32M just to be sure.

Windows Host File

Add a host entry for your local site:

127.0.0.1    localhost
127.0.0.1    devsite

httpd.conf

Under Wampserver > Apache you can edit the apache conf file. Enable the include for virtualhosts.

httpd-vhosts.conf

You can find this in the C:/wamp/www/conf/extra directory.  Add a VirtualHost entry for the local site:

<VirtualHost *:80>
    ServerName devsite
    DocumentRoot C:/wamp/www/drupal-6
</VirtualHost>

.htaccess

Within your Drupal install folder (above it is named drupal-6) uncomment the line below:

#RewriteBase /

settings.php

The first thing to do here is uncomment and set the base URL to match up with your hostname:

$base_url = 'http://devsite' // NO trailing slash!

The next thing to do depends on whether or not your live site database connection details match your local development settings.  Normally this wouldn't be the case and I would strongly advise against using live database settings in a development environment.

If you have decided to use different development user credentials then change the connection details:

$db_url = 'mysqli://username:password@locahost/devsite';

Other considerations

With this approach above I have used devsite as the hostname, this causes other issues but there is a reason behind this.  I wanted to allow our demonstrators to show off the live website when WiFi was available to them.

In order to have multisite working on the live server the VirtualHost was set up for www.livesite.com and the sites folder needed to match this.  I changed the folder name to devsite on the local Wampserver install.  This allowed access to the development site and the live site on the same machine with Wampserver running.

The only last thing that needs done is to clear the cache and clear up any block/module settings with absolute URLs (if there are any).

Project: 
Websites