The following is a guest post by Erez Elias. Erez recently attended a WordCamp and wrote to me inspired to write something about WordPress. We agreed this was an interesting topic, and one I’ve been meaning to document myself as it’s something I’ve done about 100 times in my life and there is always one little detail I gotta look up.
One big source of frustration I’ve seen from WordPress users comes when they want to move their WordPress site. As in, move the entire website from one hosting company to another hosting company. In this article I will walk you through 4 simple steps of moving a WordPress website to a new hosting.
This article assumes that you have access to both the old server and the new server. You can log into both of them via FTP or SSH.
Step 1) Back Up the Database
WordPress stores data in a MySQL database. You’ll need to move this database to move the site, which is arguably the trickiest part. You’ll need to back up the database from the old site first.
Method 1) Use a Plugin
There is a method of backing up the database using a plugin. Note that If you are dealing with a large database (say, over 50 MB) you are better off using Method 2.
WordPress has numerous plugins to backup the database, my favourite is a plugin called wp-db-backup. Once the plugin is installed and activated, select Tools > Backup in the admin.

The plugin will look for other tables in the same database. These non “core” WordPress tables may have come from other plugins you’ve used that stored data in them.

Select whether you want the backup file sent to you by email or downloaded directly and click the Backup Now! button.

Method 2) Use the Command Line
We can get a little closer to the metal if we back using SSH. SSH (Secure Shell) is a network protocol that allows you to securely access your server over encrypted connection.
First, you will need to connect to the server. You need to have the server’s IP address, username, and password. You’ll also need a command line client like Terminal for Mac or Putty for Windows.
$ ssh username@[server-ip]
If it is the first time you establish connection you will see a prompt Are you sure you want to continue connecting? Type yes and press return. Then you will be asked to enter your SSH login password. After that, you’ll be connected to the server over SSH.
Now you can export the database with the following command.
$ mysqldump -u [username] -p [database_name] > [name_your_backup_file].sql
You’ll need to replace the options in [brackets] there with your own information. The username isn’t the same here as your SSH login, it’s your MySQL access username. The database name you can get from the `wp_config.php` file if you’ve forgotten. It will also ask you for a password after this command, which is the database password, which you can also get from the `wp-config.php` file.
This will create a file (which you named in the last part of that command) which is a complete backup of your database. You may want to navigate yourself to a convenient directory to run that command in, so it will create the file there. Or put that file path in the command itself.
You’ll need to get a local copy of this database.sql backup file. One way to do that is to FTP into the server, navigate to where you dumped it, and download it from there. Or, since you’re on the command line anyway, close out the SSH connection and use the scp
command to download it. Something like:
$ scp [username]@[server-ip]:[backup_file].sql .
Step 2) Backup Files
Now it is time to back up the actual files from the old server. There are your theme files, plugins, uploads… everything. Even your WordPress core files, although this is as good a time as any to download a fresh copy of those for the new server.
To download all your files off the old server, use an FTP client like Filezilla to log into your server. Either download everything from the web root, or just the `wp-content` folder if you’re going to toss up a fresh copy of WordPress on the new server first.

It might take a while! It’s probably quite a few files and images.
Step 3) Move the Files to the New Server
Now you can log into the new server, also via FTP, and upload the files to the web root folder that you just downloaded from the old server. This also might take a little while (uploading is usually even a little slower than downloading).
Step 4) Import the Database to the New Server
In this step you will import the database to the server. This step also has two methods: via PHP myAdmin or via SSH.
Method 1) via Control Panel
Most web hosts will have some sort of control panel they offer that gives you access to things like databases. It might be cPanel. It might be Plesk. It might be some custom thing.

You’ll likely use the control panel to create the new database on your new server. It’s fairly likely the control panel gives you access to software called phpMyAdmin, which is a tool specifically for managing MySQL on the web.

Open the new database for the new site.
And now for the moment of truth: the importing of the backup `.sql` file from the old site!
Click on import tab in the top navigation.

Now you can select the `.sql` file on your local computer and run it (press the Go button).

Method 2) via SSH
If the database file is too large, like with exporting, you can SSH into the server and do the importing there. First upload the database export to the new server, then SSH into the server (instructions on that in a previous section), then run the following command to run the import:
$ mysql -p -u [username] [database_name] < [database_name].sql
Again the username here is the MySQL user, not the SSH user.
You might also need to change some options
If you are changing the URL of your website at the same time as moving servers, you might need to do some additional MySQL work. For example, if you’re changing from domain-one.com to domain-two.com, you’ll need to change the siteurl
and home
options in the wp_options table.

That won’t change hard-coded references to domain-one.com in post content though (e.g. image sources). If you need to change that too, there is some SQL you could reference in the post on moving WordPress to HTTPS that could be helpful
Hopefully, this article has helped you moving your WordPress site to a new location!
For the last step this is useful https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
I always have to export my db in small chunks (1mb or something, don’t remember right now) because there’s a file size upload limit in phpmyadmin. No big deal but is it like that just for my web host or is it a phpmyadmin limit?
You can upload your MySQL file to PhpMyAdmin as a zipped archive which is usual a lot smaller than the full database. I find this solves the issue most of the time. Also, by default PhpMyAdmin is set to a 2MB upload limit. If you have access on your server to the php.ini file you can modify the parameters (probably not possible on a shared server):
upload_max_filesize = 20M
post_max_size = 20M
If you were able to do this you would also need to restart your Apache server after the change!
Sequel Pro (it’s free despite its name) is a pretty good tool for interacting with MySQL from a GUI standpoint if you have really large databases and are struggling with file size limits.
I agree with Chris on this – you want to be close to the metal on these kind of things.
Guys, there’s only one tool you’ll ever need for moving WordPress websites:
https://wordpress.org/plugins/duplicator/
Absolutely agree. All my experience shows that at these days Duplicator are most easiest, fastest and painless choice for moving site from hosting to hosting.
Absolutely amazing! Worked perfectly for me! Thanks!
All you need is:
https://wordpress.org/plugins/all-in-one-wp-migration/
Some thoughts:
Toi Can move all the files via ssh tooI, From server to server. It’s much faster and efficient than downloading everything on tour computer to send it back to the new server.
I would use rsync wich is more “readable” but you Can also use scp. Rsync is better if you need/want to copy several times without resending everything(just resending what changed). Same thing goes for the sql dump file, of course.
“you can” instead of Toi Can. Damn you autocorrect.
Might be a little off topic but I am sure there is a rubygem called wordmove that could enter your workflow for this sort of migration
What about serialized data? :P
Interconnect IT’s search and replace script works great for serialized data. https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
You can never have too many “how to migrate your WP site” posts, or can you? I’ve followed Bill Erickson’s method for years now because it just works. Everywhere. Enjoy: http://www.billerickson.net/migrating-wordpress-websites/
For completeness, a few more tips when moving anything but a tiny blog:
Don’t download and upload all of your files one by one through FileZilla or whatever. Instead, create an archive of them, then download them all at once. Even better, download them directly on the remote server, skipping the intermediate step of download to and uploading from your own computer:
On the source machine, tar and gzip the
uploads
folder (c=create
,z=gzip
,v=verbose
,f=output file
):On the destination machine, fetch from the source machine, then untar and unzip (
x=extract
):You may need to play with permissions at this point depending on your server setup, but that’s a separate topic.
Don’t handle source files manually. As you’ll notice above, we only archived the
uploads
folder. All of your other folders should be managed in some other way (version control, or Composer, or a mix, etc.). If you don’t have any of that, you can just follow the same steps as above, but archive the entire site (eitherwp-content
, or its parent directory).Use WP-CLI to assist with URL changes in the DB. Don’t mess with URL changes directly via SQL. Just install WP-CLI (it comes preinstalled on some WordPress hosts!), then run:
See http://wp-cli.org/commands/search-replace/ for more details.
Actually, just use WP-CLI for everything to do with the DB, including exporting it from the old site and importing it into the new site. See http://wp-cli.org/commands/db/export/ and http://wp-cli.org/commands/db/import/. The good thing about WP-CLI is that it reads your
wp-config.php
file, which means no need to manually specify credentials like you would have to do if you runmysqldump
manually.I think this is unavoidable for shared hostings where there is no ssh access or any hosting panel tool to unzip a zip file.
Or is there any other reason why this is bad?
Came here for this advice. You will absolutely have to change more than just site/home URLs and for many folks they’ll try to edit them from the admin and get redirected to the old site. WP-CLI is the best but the other srrialization tools are solid too. Replacing URLs in the DB is a mandatory step where I come from.
Also great tip on compressing before moving. I would also say that if you’re already using SSH slip the local download and pull the arcjive directly from one server to the other.
Defining the new URL in the wp-config.php is useful for a domain change without having to sift through the DB:
I was about to post this too. This is the quickest option to move the website. Once you have it working, you’ll be able to quietly do the search/replace in db without hurries.
WP Sync DB (a WP Migrate pro fork) + WP-Cli plugin FTW! ;)
You can create prepared “scenarios” then push/pull whole DB live from your terminal or WP GUI.
Quick and foolproof, very easy to set up in any environnement.
As for files migration, Transmit and SFTP Sync is my weapon of choice for now (when full blown SSH isn’t available to the remote server, like entry level LAMP hosting)
But not quite satisfied with it… sometimes, permissions mismatch arises between dev/prod environnement. I’ve abandonned SFTP from CLI as i found out to be less reliable than Transmit :/
Still leaning toward a 1 command bi-directionnal migration with WP, not too far from it though.
I also have found wp-cli to be helpful for backups, if you’re comfortable with the command line a bit and you have wp-cli installed on your web host (which is normally the case!):
wp db export <backupfilename.sql>
You can use it for imports too.