You are on page 1of 4

Moving a Drupal Site from development to a New Environment

Preparation
A. Upgrade modules and Drupal core code Although its tempting to move your files and database quickly, I strongly recommend doing some preparation first. Before I move Drupal site, I always first check for any new Drupal core and module updates. If there are modules that need to be updated, I do the update before moving my site. The advantage of this is that it is easier later on to debug any problems that arise during the migration if you are already using the latest version of all Drupal code. B. Check your version of PHP and MySQL on the new and current environment Some Drupal modules require PHP 5.x. Ive run into problems before when I move over code to a new server that is running PHP 4.x. To check your PHP version, log into your new and old servers separately via ssh and run the following:
php -v

Helpful advice from Scor in the comments: The PHP CLI is not always installed and php -v might not work, or if it does it might be a different version than the one Apache runs. In any case that does not mean you cannot use Drupal on the server. Another way to check these things is to try to install a dummy Drupal core site and see if it works ok. To check what version of MySQL you are using, open MySQL via the shell on your computer and type:
status

If you are running different versions of PHP and/or MySQL on your new and old servers, be sure to check for any incompatibilities with your modules. Any module that requires PHP 5.x should say so in the README.txt document. I highly recommend making sure that your new environment uses PHP 5.x before switching. You can also check the PHP and MySQL versions of your old site via Drupal on the status page at admin/reports/status.

Moving Databases
C. Export your Drupal database using phpMyAdmin

Note: If you do not have phpMyAdmin and are not familiar with the command-line, an alternative option is to use the Backup and Migrate module. If you decide to use phpMyAdmin, I recommend truncating (emptying) the cache tables before you export your database. Go to all of the tables that start with cache_ and select the "Empty" tab. You can also manually clear Views Cache within the Views module. To export a database using phpMyAdmin, go to the database and select the Export tab. I recommend checking the Extended inserts checkbox and saving your export as a gzipped file. E. Create the database on your new environment Depending on your environmenting provider, there are many ways that you can go about creating a database. I recommend creating a database with the same name as the one on your old environment. D. Import your SQL file Once you have a database on your new environment, you can go and import the SQL file you downloaded to your desktop using phpMyAdmin. Select your new, empty database and then click the Import tab. Under the File to import option, you can upload your file. Once the file is uploaded, you can select Go. Warning: If you have a large site, importing your file into your new database can take a really long time. Do not stop the operation. Just wait. If your import times out, then you will need to look at importing using command-line or a program like BigDump. E. Moving files If you are not familiar with the command-line, you can download all of your files to your desktop and then upload them to your new environment using FTP. However, this process can be very slow. I recommend using secure copy (scp) instead. To use scp, you first need to know where your files are on your current site. Log into your old site using ssh or ftp and get the path to your web directory from the server root. Once you are in the correct directory, enter:
pwd

Copy the output to somewhere youll be able to find again. Next, log into your new environment and go to the directory where you want the new files to go. The following worked for me:

scp -rp myusername@www.myoldenvironment.com:[/home/myusername/www.myoldenvironment.co m/public_html]/* .

The part after the colon, in brackets, is the path you just copied on your old site. The brackets are just here as an example, do not include them when you scp. This command copies everything in the public_html folder on my old environment to the current folder of my new environment. the -p flag preserves permissions and the -r flag recursively copies so that you get the content of your folders. Be sure to check and make sure that the .htaccess file copied over as well. Note: You could also use subversion, git or another version control system to download the new files provided that you environment your repository on a different site than your old environment. If you are doing this, then you probably have already moved past this step.

Setting Up and Testing the New Site


F: Edit Settings.php To correctly configure your database, edit your settings.php with your new domain information. Be sure to scan through settings.php and remove any settings that you may have added that only relate to your old environment. G: Edit Your Environments File You can test your site locally by editing your environments file. By editing your environments file, you will be able to see what your site looks like before making the DNS switch. I have a Mac and edit my environments file in private/etc/environments. To test it, I added a new line where the first column is the IP address of my new site and the second is the domain Im testing.
IP address of new site 69.123.11.11 www.mydomainname.com www.juliakm.com

The environments file is a little trickier to find on Windows machines. This Wikipedia article gives a list of environment file locations for different operating systems. H: Test your site locally Once you have your new site showing up using your environments fix, make sure to test your new site. I recommend trying the following:

Log in Check your site status at admin/reports/status Create a post

Edit an existing post Post a comment View your module list at admin/build/modules/list

I: Fix any problems A few problems that Ive run into before are:

Not making my files/ directory writable Not having the GD Library installed at my new environment

For the GD Library, youll have to talk to your new environmenting provider. For the files directory, go to the directory above your files directory and enter via command-line:
chmod -R 755 files

If you are confused about the chmod command, search for it on Drupal.org. There is a wealth of information available there. J: Undo environments file changes Go back to your environments file and reverse any changes you made. K: Set up your cron job You can do this via crontab or a tool provided by your environmenting company.

You might also like