Deploying WordPress the Hard Way

February 3rd, 2011

I had a WordPress deployment ordeal this week.  I developed a site with WebMatrix, and I needed to deploy it to an internal server that did not have the Web Deploy service running on it.

My first thought was to install Web Deploy.  I gave up.  Among my many skills, setting up Web Deploy does not appear.

I’d already added a bunch of links, uploads, and a few custom tweaks that wouldn’t be caught by a simple export/import through the WordPress admin interface, so I had to roll my own method to back up the entire database and get it online.  I pulled heavily from the WordPress Codex, and found a few other snippets online.  Here, in all its horrific glory, is the Hooker Method of moving a WordPress installation from a development box to a server.

NOTE: I’ve done this exactly once, and there was a lot of trial and error along the way.  PLEASE make backups of all of your files before you attempt to follow my steps.  While following these directions should not present any danger to your original work, I do not offer any guarantees that the steps that worked for me will work for you.

1. Back up the database

Assuming you’ve got the whole thing already working on your laptop (or whatever it is that you use), your next step is to run a mysqldump to create a backup of the file.  mysqldump is included with MySQL, but it is not referenced through the MySQL command line client (because it’s a separate executable).  Here’s what you do:

  1. Open a command prompt.
  2. Browse to the directory where the mysqldump.exe file lives (on my standard installation, it’s in C:\Program Files\MySQL\MySQL Server 5.1\bin).
  3. Type at the prompt: mysqldump -u username -p database_name > “path/filename.sql”
    1. username: Your database username
    2. database_name: The name of the database you’re copying
    3. path: The location where you want the file to save.
    4. filename: Whatever you want — it’s the name of the backup file you’re creating.
    5. example: mysqldump -u samhooker -p wordpressDB > “C:\Users\Sam\Desktop\wp-backup.sql”
  4. Hit enter, and you’ll be asked for your password.  Enter it, hit enter again, and you’re done.

Note:  You can enter a password after the -p, which can be handy if you’re creating a batch file.  I leave it out so it’ll prompt me — it then displays asterisks as I type, which helps protect my password from anyone looking over my shoulder.

In the example listed above, I created a backup of my database named wp-backup.sql on my desktop.

2. Transfer files to your server.

You’ll need to have a complete copy of your WordPress directory (the one with your wp-admin, wp-content and wp-includes folders), as well as the database backup that you made in step 1.  Use FTP or whatever other means you use to get those files uploaded to the proper directory on your web server.

3. Create the database and database user.

This assumes that you already have MySQL installed on your web server, and have login credentials that will allow you to create a database.

  1. Start the MySQL Command Line Client.  You should be able to get there by going to Start –> All Programs –> MySQL –> MySQL Server 5.1 –> MySQL Command Line Client.
  2. You’ll get a command prompt that asks you for a password.  Enter the root password for your MySQL installation.  If you don’t have the root password, you can log in with another user account (that has admin access to the database you’re working with) by taking the following steps:
    1. Open a command prompt.
    2. Browse to the directory where your mysql.exe file lives (mine is C:\Program Files\MySQL\MySQL Server 5.1\bin).
    3. Type mysql.exe -uusername -ppassword and hit Enter.
    4. You should be logged in and have a mysql> prompt.
  3. Type at the prompt: create database database_name;
    1. database_name: the name if the database you backed up in step 1.
  4. Type at the prompt: grant all privileges on database_name.* to ‘database_user‘ @ ‘host‘ identified by ‘password‘;
    1. database_name: The name of the database you just created.
    2. database_user: The database user you created with your original installation
    3. host: the domain on which the database resides, often localhost
    4. password: The database password you created with your original installation
    5. Note: You can easily find all of your previously-entered information in the wp-config.php file in your WordPress directory.
  5. Hit enter, and the database user will be set up.

4. Install WordPress

Browse to your WordPress installation in a web browser, and you’ll get the wp-admin/install.php page.  Fill in the requested information, and it will connect to the database you’ve set up.  You’ll be able to log in now, but the database will be populated with the familiar old “Hello, World!” garbage.  Time to apply the database!

5. Import the database

Now that you have a database and user set up on the server, you’re ready to import the backup you made in step 1.

  1. Open a command prompt and go to the bin directory mentioned in step 1.
  2. Type at the prompt: mysql.exe -uusername -p database_name < “path/filename.sql
    • example: mysql.exe -usamhooker -p wordpressDB < “C:\Users\Sam\Desktop\wp-backup.sql”
  3. Hit Enter.
  4. Enter your password, hit Enter again.

Depending on the particulars of your installation, you may still have a few wrinkles to iron out — namely, you may have to fix the siteURL info.  There are a lot of factors to consider here, so if you’re having issues, I recommend having a look at this Codex article: Changing the Site URL.

Happy deploying!  If I missed any steps, leave a comment and I’ll edit later.

Leave a Reply