How to move a WordPress site to a new VPS
Moving a WordPress site means moving three things: the files (above all the wp-content folder), the database, and the DNS record of your domain. The easiest route is a migration plugin. By hand, you copy the files, export the database, load it on the new server and fix the addresses if they changed.
The order is the same whichever method you choose: back up, test on the new server, and leave DNS for last. Don't shut down the old server until the new site is working.
Before you start
- Take a full backup. Keep a copy of the files and the database on your own computer. The official WordPress migration guide also tells you to back up before any change to the database.
- Find out the size. How many MB are the
wp-contentfolder and the database? That decides which method suits you. - Compare versions. Does the PHP version on the new server work with your old plugins? Update an incompatible plugin before you move it.
- Lower the TTL. A day or two before the switch, set the TTL on your domain's DNS records to 300 seconds. That way the old address doesn't linger in caches for long.
- Check where your email lives. Changing the A record doesn't touch your MX records. If your mail runs on the site's server, it has to be moved separately.
Method 1: move with a plugin
Migration plugins bundle the files and the database into one package and unpack it on the new site, and most of them fix the addresses too. There are three common approaches:
- Uploading a package in the browser. You build the package on the old site, install the same plugin on the new WordPress and upload the package (All-in-One WP Migration works this way, for example). This approach runs into the server's upload size limit.
- Placing the package with SFTP. Plugins such as Duplicator ask you to copy the archive and an
installer.phpfile into an empty folder on the new server, then openinstaller.phpin a browser. You need to create the database and its user beforehand. When you finish, deleteinstaller.phpand the archive, because anyone who knows the address could run the installer again. - Restoring from remote storage. With a backup plugin such as UpdraftPlus, you connect the same cloud storage on the new site and find the backup with the "Rescan remote storage" link. You never upload the big file through the browser.
The 64 MB limit on the ready-made WordPress server
On Seturack's ready-made WordPress server, you can upload at most 64 MB in one go. Plugins that take a package through the browser hit that limit. If your package is bigger, use the remote-storage restore or move the site by hand. Because the ready-made app runs in Docker, the files don't sit where they would on a classic install. For a large site you will move by hand, a clean Ubuntu server with Apache or Nginx installed is more predictable.
Method 2: move by hand
These steps are for a classic install where the files live in /var/www/html. If you run WP-CLI as root, add --allow-root to its commands. On the old server, inside the WordPress folder:
- Export the database outside the web folder, because a dump left in it can be downloaded by anyone who knows the address:
wp db export ~/site.sql. Without WP-CLI, usemysqldump -u USER -p DATABASE > ~/site.sql. - Archive the files with
tar -czf ~/files.tar.gz . - Copy both to the new server with
scp ~/site.sql ~/files.tar.gz user@NEW_IP:~/
On the new server:
- Create an empty database and a user for it.
- Unpack the files into the web folder with
tar -xzf ~/files.tar.gz -C /var/www/html - Update the database name, user and password in
wp-config.phpwith the new values. Give ownership to the web server user (www-dataon Debian and Ubuntu). - Import the database with
wp db import ~/site.sql. The command reads its settings fromwp-config.php, and it does not create the database for you.
If the domain stays the same, no address fix is needed. If it changes, replace the old address with the new one. Try it with --dry-run first, and leave the guid column alone:
wp search-replace 'https://old.com' 'https://new.com' --skip-columns=guid --dry-run
If the output looks right, run the command again without --dry-run. Don't do a plain find-and-replace on the database, because serialized data can break. WP-CLI handles that data correctly.
Test on the new server before switching DNS
Add the new server's IP address and your domain to the hosts file on your computer. The file is at C:\Windows\System32\drivers\etc\hosts on Windows and at /etc/hosts on macOS and Linux:
203.0.113.10 example.com www.example.com
From then on, only your browser opens the new server, while everyone else still sees the old one. Try the login, pages, images and forms, then delete the line. An HTTPS certificate is usually issued once DNS points at the new server.
The DNS switch
- If the site takes writes all the time (a store, memberships, comments), put the old site in maintenance mode, take the database one last time and transfer it. Otherwise, orders placed during the switch are lost.
- In your DNS panel, point the A record at the new IP address, and do the same for www. The article on connecting your own domain shows the steps.
- With a low TTL the change spreads quickly. Some networks may keep the old record longer.
- Confirm that HTTPS works on the new server.
- When all is well, put the TTL back to its old value. Keep the old server for a few days, then shut it down.
Checklist after the move
- Open Settings > Permalinks and click Save to refresh the rewrite rules.
- Open the home page, a post, an image and the contact form.
- Look for mixed-content warnings. Fixing the addresses solves most of them.
- Test email sending and check the settings of your SMTP plugin.
- Clear the cache of your caching plugin.
- Delete
~/site.sqland~/files.tar.gzon both servers. Both contain sensitive data. - Under Settings > Reading, confirm that the box that discourages search engines is not ticked.
If you move with a plugin, starting from an empty WordPress makes it easier. A server with WordPress pre-installed is ready in roughly 3.5 to 4 minutes. Have a look at the WordPress server page.
Comments0
No Comments Yet
Be the first to share your thoughts.
Please sign in or sign up to leave a comment.