Moving your Drupal installation to a new directory

Last modified: January 7, 2009 - 18:26

The text below refers to Drupal 4. See the comments for suggestions for Drupal 5 & 6.

If for instance you need to move your installation from www.mysite.com/development/ to the root directory of www.mysite.com, just follow these simple steps:

Copy Files

Copy the files of your Drupal installation from the old directory to your new directory. Make sure you include .htaccess.

Change Path

In your new directory, open the file (4.5 or earlier) includes/conf.php or (4.6) sites/default/settings.php

Look for a line that begins with "$base_url = ", update this so that $base_url equals the path to your new directory. Save the file and close it.

You might need to modify the .htaccess file as well.

Update Cron

If you set up Cron on your old installation, make sure you update it to point to your new installation.

Delete Old Directory

Test that everything is working in your new installation. If so, it is now safe to delete the files in your old Drupal directory.

Two more items

lsommerer - March 17, 2008 - 13:22

In addition to the steps listed above, I had to do the following two items so that my site appeared correctly after I moved it (drupal 5.3):

  • Under Administer -> Site Configuration -> Performance disable caching mode. It appears that you can immediately turn it back on, but it needs to be disabled to recognize that your CSS is now in a new location.
  • Under Administer -> Logs -> Status Report click on run cron manually. Before cron was run, images would not appear that were added to nodes with image_assist.

Another problem - Internal Links...

jfall - April 12, 2008 - 01:36

In a traditional HTML site, use of 'relative' links allows you to move the entire site to a new directory or even a new domain without breaking 'internal links'. However, for many Drupal sites, relative links are not very meaningful because the URL paths do not correspond to physical directory structure, as in HTML sites.
Thus, links coded within a node to a URL on the same site (internal link) will usually use an 'absolute' path (full URL) or a 'server relative' path (relative to server root e.g., /some/path) - in either case, the link will be broken when you move your site to a new directory. This DOES NOT apply to links generated by Drupal (e.g., menus, taxonomy terms, etc.) - only to internal links that have been 'hard coded' into, e.g., the body of a node.

AFAIK, there is nothing to do about this - just be aware of the problem so you can correct any internal links after moving your site.

There's more to consider if moving a Drupal installation

asb - April 12, 2008 - 16:32

I followed these instructions and moved a Drupal 5.7 installation from /oldpath to /:

* copied the files from /oldpath/* to /*, including .htaccess;
* edited .htacces and changed all references to /oldpath;
* edited Apache's configuration for the vhost, restarted httpd;
* edited sites/default/settings.php and changed all references to /oldpath;
* ran crontab -e and changed all references to /oldpath;

The result: accessing the site at the new location results in a WSOD (blank page in browser), accessing /node results in a WSOD, also. Accessing /admin is possible, however I can't log in by entering my credentials at /user (access denied); however, entering them at /?q=user works. Apache's error log reports nothing but "File does not exist"; /update.php is accessible and working. In this instructions some crucial steps seem to be missing - the site is dead.

Other steps that might be necessary:

* Login without blocks and menu - /?q=user
* Disable Clean URLs - /?q=admin/settings/clean-urls (http://drupal.org/node/5590)
* Disable Drupal caching - /?q=admin/settings/performance
* Clear the Views cache (if using views) - /?q=admin/build/views/tools
* Repair absolute or relative system paths for contributed modules that rely on 3rd party software residing somethere else in your system
* Check the contents of the "systems" table in MySQL

There's definitely more to consider if moving a Drupal installation than these simple steps!

* Do a fresh setup at something like test.example.com, check if everything works, use the working configuration files from the "test" setup and adapt them for www.mysite.com/oldpath/
* Overwrite the moved setup with a fresh installation (save .htaccess and sites/default/settings.php to a secure place, and have your database credentials ready); the installer will recognize an existing database and should create a fresh configuration.

In my case, nothing of this worked. Even /?q=admin became inaccessible at some point. It was NOT possible to get the moved Drupal installation running from www.mysite.com/ instead of www.mysite.com/oldpath/. So be prepared to UNDO all the steps described before when falling back to /oldpath. So BE PRPARED FOR TROUBLE!

With lots of digging, I discovered the problem: A contributed filter (PEAR_Wiki_Filter) had a path that was pointing to the old location. I discovered this by diasbling ALL contributed modules: If thes reside in ../modules, move all of them to something like ../modules_inactive, then moven them back one by one until the site dies. DO NOT disable Drupal's core modules when doing this!

If you should succeed to move your Drupal site from a subdirectory to the server root, all search engine paths will run empty. On http://drupal.org/node/144643, there are some notes on Rewrite rules that can fetch those old paths (stripping /oldpath from the URL) and make them work again. In my case, I wanted everything pointing to /olddir to remain ransparently accessible. One simple rule in .htaccess did the job:

RewriteRule ^olddir/(.*)$ /$1 [R=301,NC,L]

This catches every request to /olddir and rewrites it to the server root.

There are some discussions on moving a Drupal site, e.g.

* Move drupal site to another location?, http://drupal.org/node/140714
* Moving Drupal from subdirectory to directory, http://drupal.org/node/20853

Alos, there might be alternative ways, e.g.:

* Drupal installed in subdirectory but made to appear in root, http://drupal.org/node/144643

Good luck & Regards, asb

Thanks!

manerhabe - May 15, 2008 - 02:50

Worked perfectly except for the .htaccess rewrite rule to redirect old links from search engines. This worked for me instead:

RewriteRule ^/?olddir/(.*) http://site.com/$1 [R=301,L]

I also had to put this directly under:

<IfModule mod_rewrite.c>
  RewriteEngine on

which was on my line 66 of my root .htaccess. Thanks a ton!

P.S. http://validator.w3.org/checklink is also useful to check for broken links

That doesn't leave much hope!

Steven_Bradford - December 14, 2008 - 06:21

Yeah, I tried that technique in the original post, and it failed horribly.

I wish I'd discovered this thread early on. I might not have tried to create a drupal site for an existing domain if I'd known that the step of moving it from test to the top directory would be so far beyond my current understanding. I was afraid this would happen.

Every FAQ and Book and Install guide I've seen seems to assume that we are building new sites from scratch in freshly minted domains. But obviously that can 't be the case.

I'm afraid I'm going to have to hire someone to move the site I've been working on for weeks to it's intended domain, cause I can't figure this out! ;-) .

Theme Registry

ezraw - November 26, 2008 - 02:47

If the location of your temp directory has changed, you will need to rebuild the theme registry. This is probably not an issue if you are just moving to a new directory on the same server, but if you are moving to a new server the theme may not display correctly until the registry is rebuilt.

To rebuild the theme registry you can either reselect the module at admin/build/themes/select or clear the cache at /admin/settings/performance.

For Drupal 6.8

Vako - January 2, 2009 - 07:13

I had my test Drupal installation in a folder /cms, I moved it to the root folder "/" by simply using the following steps:
1. Cleared the cache and then disabled caching: Home » Administer » Site configuration
2. Created a Temporary index.html file in the root folder that displays the Site us under maintenance text (since moving the site might take considerable amount of time)
3. Deleted all the files in the root folder, except the index.html and the /cms folder
4. Moved the contents of the /cms folder to the root using the cPanel->File Manager->Move command (which is faster than regular move and doesn't corrupt any files)
5. Deleted the .htaccess file in the root and replace it with the one from /cms folder
6. Update the .htaccess file as follows (check the bold line):
# 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 /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
RewriteBase /

7. In sites/default/settings.php make sure that the "$base_url = " is pointing to the correct URL of your site where Drupal is installed in now.
8. Deleted the index.html file create in step 2
9. Re-Enabled the Cache in Home » Administer » Site configuration
10. Finally I had to update some hard-coded image locations and menu options.

Voila! that's all you need. Good Luck!

Vako- That was awesome!

jkuper - January 24, 2009 - 00:52

Vako-

That was awesome! Thanks for the help. One question for you though... once I got the site moved, I tried to delete the /drupal directory from the c-panel and it won't let me. Any idea why?

Thanks again!

-J

Sure

Vako - January 24, 2009 - 20:07

Hi jkuper, the original folder is locked because of the settings.php file in the sites\default folder. 1st make sure that you have a copy of that file locally.
To delete the folder:
1. Use cPanel's File Manager
2. Change the permissions of the folder and all the files in it to 777.
3. Delete the folder, if still unable to, then delete each file individually and make sure their permissions are set to 777 as well.
4. In dire situation when you are still unable to delete it, call your hosting provider and they will delete the folder and contents.
5. If the site becomes inaccessible after you delete the folder, then you have to copy the settings.php file from your local system to the server at sites\default folder.

Thanks a million Vako, your

castawaybcn - March 26, 2009 - 10:38

Thanks a million Vako, your instructions worked like a charm!!

You're welcome

Vako - March 27, 2009 - 06:25

You're welcome

 
 

Drupal is a registered trademark of Dries Buytaert.