How to Migrate Drupal Site to a local Development Server & Fix Clean URLs
This is done on a Drupal 6 site, there are easier ways but I couldn’t touch the site by adding any other modules.
First thing to do is to disable clean URLs in the live site - » Administer » Configuration »Clean URLs, disable and save. If you have failed to do this step there are some troubleshooting tips below to fix.
Second thing is to download a back up of the drupal site, if you are using cPanel you can download the home directory and a copy of the mysql database from the backup section in cPanel.
On your local development server create a directory in your web sharing root and move both files in to it, in an OSX environment that will be in your home directory, Sites folder, ~/Sites/ for this tutorial the folder will be named “localdrupal”, so the shared directory is ~/Sites/localdrupal
Uncompress both archives.
Move into the local shared directory
cd ~/Sites/localdrupal
Create a new database in mysql, mine will be called localdrupal and add in the old database
mysql -u root -p -e "create database localdrupal;"
mysql -u root -p localdrupal < [.sql olddatabasefilename]
Move the contents from the decompressed archive into the local shared folder, the archive may have a couple of folder levels, we are after the old web root typically “public_html”.
You can move all the visisble files in with the GUI, but you need to also move the hidden “.htaccess” file
~/Sites/localdrupal : mv ~/Sites/localdrupal/backup/public_html/.* ~/Sites/localdrupal/
You’ll get an invalid argument error but it still does the job.
Next up is to edit the “settings.php” file to reflect the new database name and database owner, in this command below we are also changing its permissions to write so we can change it.
cd ~/Sites/localdrupal/sites/default/ ; chmod a+w settings.php ; nano settings.php
I like to set the base URL
$base_url = 'http://localhost/~username/localdrupal'; // NO trailing slash!
More importantly the new database details
$db_url = 'mysql://root:password@localhost/localdrupal';
OK so here is where your mileage starts to vary – hopefully it has been smooth and the full web site resolves to the new URL.
http://localhost/~username/localdrupal
Troubleshooting!
However if it doesn’t work that cleanly – you may only get the home page and all the others are not found, you may not be able to log in or pages are not found – all of this may be down to the clean URLs. Below are some troubleshooting techniques that may help.
Fix the Rewrite Base in the .htaccess file if you have your folder in a sub-directory – this is very important
# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
RewriteBase /~username/localdrupal
Check to see if all is OK – otherwise carry on with the troubleshooting.
The database may need some sql injection to rid it of clean URLs. Run it either in phpmyadmin or in the shell.
UPDATE variable SET value = 's:1:"0";' WHERE name = 'clean_url'; DELETE FROM cache;
or in the shell
$ mysql -u root -p mysql> use localdrupal; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE variable SET value = 's:1:"0";' WHERE name = 'clean_url'; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> DELETE FROM cache; Query OK, 5 rows affected (0.03 sec) mysql> \q
If pages are still not found try logging in as the admin using unclean URL so you can turn clean URLs back on:
http://localhost/~username/localdrupal/?q=user
Make sure in your httpd.conf file that the allow overrides are set to on to allow the .htaccess rules
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All
And that the mode rewrite is loaded
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Your site may have a httpd conf file outside of the main httpd.conf file located at /etc/apache2/users/username.conf make sure overrides are set to All
<Directory "/Users/username/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Any changes made to the httpd.conf or username.conf files will need an Apache restart:
sudo apachectl restart
Hopefully one of the above fixes any errors – the whole clean URL process can be a royal pain, please check at Drupal if you are still in a jam.
Related posts:
- Fastest Way of Installing Drupal 6 on Mac OS X
- Sort out your Canonical URLs in Drupal – Force http://www
- Fastest Way of Installing Drupal 7.14 on Mac OS X 10.7 , 10.6
- How to Install mcrypt for php on Mac OSX Lion 10.7 Development Server
- Installing Piwik – Real Time Web Analytics – WordPress Joomla and Drupal


July 11, 2011 
