If you ever have the need to move a WordPress site or a network of WordPress sites to a new server, it can be an outright frustrating task due to all of the settings and data that get accumulated over time. This article is written to be a quick reference for this seemingly daunting task. Eventually I may turn this article into a script to automate the process [EDIT: I have done this successfully] – and/or maybe even a WordPress plugin. If you think this would be useful, feel free to let me know.
Follow through these steps and you might have WordPress up and running on a different server in 30 minutes depending on the size of your data.
Back Up Database
In order to move your database to the new server, you’ll want to do a database dump. A database dump is a file where all of the information from a database is stored into multiple queries. When you import the dump file into the new database server, these queries are executed one by one until the database is built.
Dump the database
mysqldump -v -u root -h database.blog.com --database my_wp_db --skip-lock-tables > my_wp_db.sql
Copy the database dump to the new web server
Because this article is not intended to help you actually set up a web server, it is expected that you have already configured the new database server to allow access from the new web server. After the database dump is complete, you should see a file called my_wp_db.sql in your current directory. Copy the .sql file to the new WordPress server.
scp -i ~/.ssh/your_private_key ./my_wp_db.sql root@my_new_server.com:~/
Change the domain name in the MySQL dump file
Using sed, you can execute one command and it will modify a whole entire file without even opening it.
sed -i 's/my_old_server.com/my_new_server.com/g' ./my_wp_db.sql
Import the database dump file into the new database server
SSH into the new web server
ssh -i ~/.ssh/your_private_key root@my_new_server.com
Import the database dump into the new database server
mysql -v -u root -h new.database.blog.com -p < ./my_wp_db.sql
Copy WordPress Files
The easiest way to make a clone is to do a direct copy of the whole WordPress file system (rather than downloading a new WordPress installation and installing it from scratch).
I keep my WordPress installation in /var/www/ on the server, so here’s what I did to move the files to the new server (as the root user):
tar -czvf ~/wordpress.tar.gz /var/www
scp -i ~/.ssh/your_private_key ~/wordpress.tar.gz multisite.blog.com:/var/www/
ssh -i ~/.ssh/your_private_key email@example.com
tar -xzvf ./wordpress.tar.gz
mv ./www/* ./
Open wp-config.php and change the following lines to match the database credentials for the new database server:
/** MySQL database */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
Scroll down through the file and find this line a bit further down…
/** Domain Name */
define( 'DOMAIN_CURRENT_SITE', 'multisite.blog.com' );
If you have domain mapping enabled on the production server, but are only testing on the new server, you will probably want to disable any domain mapping. You will know if you have domain mapping if a CNAME’d mywordpress-site.com brings up mywordpress-site.multisite.blog.com.
In order for WordPress to serve any sub-domains in the multi site instllation, you will need to add a couple of DNS records so that they point to the new WordPress server. In this case…
domain = blog.com
// create a DNS "A" record called "multisite" and point it to the IP address of the server
[A] multisite => 192.168.0.100
// create a wildcard DNS "A" record with an asterisk, a dot, and multisite
[A] *.multisite => 192.168.0.100
In the end, you will have two DNS A records:
Apache Wildcard Host
In your Apache host configuration file (usually /etc/apache2/sites-available/000-default (or sitename.conf) or at the bottom of /etc/apache2/httpd.conf or /etc/apache2/apache.conf, you’ll want to make sure that you have the following:
The above lines tell apache to respond to anything.multisite.blog.com
Now that you have made it through these steps, try out your new WordPress site. If you notice that I missed anything, or if I did something that doesn’t look right, please make a comment below and let me know.