How to move your WordPress site to a VPS using Command Line

There are several reasons for you to want to move your WordPress site to a VPS, most notably, your site has outgrown shared hosting or you want to improve performance by leveraging caching functionality. Transferring a WordPress site is not complicated if you do your prepwork first. First you need to make sure you have signed up for your VPS service. When you sign up, you will receive an email with the subject “New Hosting account information from ServerGrove”. This email contains all the information you need to access your hosting service.

Step 1: Prepping your old WordPress site for transfer

A WordPress installation has main components:

1) The installation (the files)
2) The database

You will need to prep both of these to transfer. This tutorial covers transferring your Wordpres site using SSH. This is the fastest but not recommended for people who are unfamiliar using SSH.

Open your (or PuTTY for Windows users) and type the command to connect to your old host.

ssh -p 22123

* User is your username (if this is a shared host most likely your username will be your FTP user)
* is your domain name or your IP addess
* -p 22123 is the port number. If you are a ServerGrove shared hosting client your port will be 22123, other hosts often use port 22.

You will get a password prompt.

Once you log in, navigate to the directory where your WordPress is installed.

Once you’re at your WordPress installation, you will need to get a dump of the MySQL database. To do this, you’ll need to know the database name, the server, the username, and password. If you don’t remember this information, it is all in your wp-config.php file located in the root directory of your wordpress installation. Get the dump using the following command:


* USERNAME is your database username
* DATABASENAME is the name for your database
* FILENAME.sql is the name of the file you wish to export your database to. It can be anything as long as you remember the name.

Once you are done with the database dump you will want to compress all your WordPress files and you SQL file into one to make the transfer easier. Make sure you are in your WordPress directory. To compress all the files run the following command to compress everything into a file called wordpress.tar.gz:

tar cvzf wordpress.tar.gz *

Step 2: Importing your WordPress Install on your VPS

Next you will need to create a database and a database user for your yourpress installation.

SSH into your VPS with the following command:

ssh -p 22123

* User is your username (if this is a shared host most likely your username will be your FTP user)
* is your domain name or your IP addess.
* -p 22123 is the port number.

Login to MySQL:
$ mysql -u root -p

* root is your user.
* This will prompt you for a password. You can reset your MySQL root password in the control panel

Create a new mysql database called wordpress:

mysql> CREATE DATABASE wordpress;

Create a new user called wpuser for database wordpress

mysql> GRANT ALL ON demo.* TO user1@localhost IDENTIFIED BY 'mypassword';

Note: GRANT ALL means all privileges. She the user is permitted do anything: read, modify or delete data, but only on tables in the wordpress database. The user cannot access any other database.

Next you will need to move your compressed site from your old server to your VPS. We will do that using FTP with the command line. First navigate to the directory where you want your WordPress install to be. Then type:


This will promt you to login to your old account. Navigate to the directory you left your compressed file using the cd ann the ls commands. Next you need to get your tarball (compressed file). Run the command:

get xvzf blog.tar.gz

Once the file has finished transferring, unzip the file using:

tar xvzf blog.tar.gz

This should have uncompressed all your files. You can verify by using the ls command.

The next step is to import your sql file you created earlier, into the database you just created. It’s another one line command:


Next go to the VPS IP and check if your blog installed correctly.

Switch your DNS

Once you have transferred the site you need to switch your nameservers so the domain ponts to your VPS. ServerGrove nameservers are:

You can change these with your current domain registrar or in the client area if you transferred the domain to ServerGrove. Please allow enough time for the DNS change to take effect.