Sunday, February 28, 2010

Relocating Drupal Installations

As I said yesterday, before I disrupt my Web presences with Drupal updates, I'm going to break them locally. So today's project is to create a replica of the installation of Drupal on localhost here on my Linux box, set up as an Apache2 server. I'm hoping that if I write it all out once, I can do this over and over without too much trouble. (Please don't laugh. Sometimes it does work that way.)

  1. Go to the /var/www/ directory, and make a directory to contain the Drupal installation you're cloning. the URL will be http://localhost/yourDrupaldirectory/
  2. Grab a copy of the website. The cPanel tools can create a compressed back-up copy of the website, and let the user download it through the browser. When doing this, be sure you just compress and back up the Drupal portion of the website--there's all sorts of extraneous stuff you don't need, like the email accounts. Then you can expand it using tar on the command line. Here's the syntax for tar:

    tar -xvwzf myfile.tar.gz to uncompress (untar) the myfile.tar.gz file in the current directory where "x" is for "extract;" "v" is for "verbosely list files processed;" "w" is for "ask for confirmation for every action;" "f" is for "use archive file or device ARCHIVE;" and "z" is for "filter the archive through gzip." To skip the annoying request for confirmation, use tar -xvzf myfile.tar.gz

  3. Alternatively, you can download the files and directories you want via ftp and use phpMyAdmin to export the contents of your database to a .sql file, which you can download. See How to backup your Mysql database with phpMyAdmin for exactly which buttons and boxes to click to get the .sql file for the whole database.

  4. Once the files are uncompressed and arranged the way they're supposed to be, It's time to recreate the database. It's probably a good practice to create a new user with password and new database for that user, rather than use the root user for the new database, so:

    1. Log into phpMyAdmin as root user.
    2. Click on "Privileges" and then "Add a new User"
    3. Set "Database for User" option to "Create database with same name and grant all privileges" and check all "Global Privileges."
    4. Hit "Go" and do what phpMyAdmin tells you to do. Remember to write down your user and database name, and the password you selected. Your database won't have any tables, but don't worry. We'll fix that next.
  5. PhpMyAdmin has an "Import" option, but it can only import very small databases. My Spiceridge database doesn't have much in it at all, but it's about three times too large for phpMyAdmin to import. Not a problem, though, because it's really easy to do this through the command-line program mysql. Here's the command: mysql -u username -p databasename < databasedump_dp.sql and it will prompt you for the password after you hit enter. This creates all the tables and populates them in one step.

  6. Now you've got the files on localhost and, and the database in your local MySQL database, you just need to update your settings.php file, which is in /var/www/your_Drupal_directory/sites/default/. You'll have to give yourself write permissions via the command-line program chmod a+w settings.php Then go into a text editor, and look for this:

    * Database URL format: * $db_url = 'mysql://username:password@localhost/databasename'; * $db_url = 'mysqli://username:password@localhost/databasename'; * $db_url = 'pgsql://username:password@localhost/databasename'; */ $db_url = 'mysql://yoursecret stuff';

    Modify it to include your local user name, database name, and password in the format they demonstrate for you. It's probably best to remove the write permissions when you're sure everything is working.

  7. Point your browser to http://localhost/yourDrupaldirectory/ and you should see your Drupal website.
  8. After fussing about with the Drupal site's documentation, the search engines showed me this short and sweet set of directions: Moving A Drupal Site From One Host To Another - How To. This worked for me.

No comments: