Move a WordPress website to a new VPS/server

I have moved wordpress sites between servers several times before.
Up until recently I have used plugins such as Duplicator etc.
But I thought that there has to be an easier (and free) way of doing this.

Here is how I did it using WP-CLI on a Ubuntu 24.04 server running MariaDB and Nginx.

Here’s what you need

SSH access to both the new and old server with root privileges (sudo)
An SSH client (i.e Putty) and an SFTP client (i.e WinSCP or Filezilla).
That’s about it. The rest we’ll take care of here.

Install WP-CLI

First off we need to get WP-CLI installed.
Like always, update and upgrade before installing.

sudo apt update && sudo apt upgrade -y

Install PHP and some required extensions to run WP-CLI.

sudo apt install php php-mbstring php-xml php-curl -y

Go to your home directory and install WP-CLI.

cd --
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Make it executable.

chmod +x wp-cli.phar

Move it to a global system path.

sudo mv wp-cli.phar /usr/local/bin/wp

Make sure it’s working.

wp --info

You should get something like:

First steps done. It is now ready to use.

WP-CLI is a powerful tool if you often install or manage WordPress sites.
Check out https://ultahost.com/knowledge-base/install-wp-cli-ubuntu/ if you want to see more of what you can actually do with it.


Prepare WordPress for the move

Go to the directory where the WordPress site you want to move is located.
In my case it’s:

cd /var/www/html/wordpress

To export the database type..

sudo -u www-data wp db export

If that throws you an error that the user isn’t availabe or similar you CAN do it as root.
It is NOT recommended for safety reasons, but that’s what I did… sue me..

Anyhow, this is how you do it.

sudo wp db export --allow-root

Leave a Reply