• Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Coolest Guides on the Planet

coolest guides on the planet

Come for the software, stay for the community

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

How to Migrate Drupal Site to a local Development Server & Fix Clean URLs

July 11, 2011 3 Comments

This is tested on a Drupal 6 site, there are easier ways to do this 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 further 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, in an OSX environment that will be in your home directory, Sites folder, ~/Sites/  or  /Library/WebServer for this tutorial the folder will be named ‘localdrupal’, so the shared directory is at ~/Sites/localdrupal

Uncompress the archive.

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;
phpmyadmin-delete-cache-url

phpmyadmin-delete-cache-url

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

    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all

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.

Cats: Drupal, macOS, Tech Tags: clean urls, development, drupal, hosting, local, migrate, mysql, urls

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Copyright © 2023· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2023 · gee on Genesis Framework · WordPress · Log in