Migrate your WordPress website to a new virtual server


migThe migration process may sound complicated, but it’s really quite easy. All you need is an SSH access to both old and new servers. In this guide, we will show you how to move your WordPress website and  other data from your old hosting provider to your new virtual server with almost no downtime.

Preparation

To minimize the propagation time first you will need to lower the TTL (Time To Live) value for the domain you will migrate. Next, login to your new virtual server and install all necessary services (MySQL, PHP, NginX ..etc). We will not go into details in this part, because you can check our excellent tutorial and you’ll find step-by-step instructions about how to setup MySQL, PHP-FPM and NginX on a Debian/Ubuntu server.

Migration

Once the VPS is setup, the next step is to migrate your website, data and configurations over to it.

Do the following on your new virtual server

Create a new MySQL database (preferably with the same username and password as you’re using on your old server)

    mysql -u root
    CREATE DATABASE DATABASE_NAME;
    GRANT ALL PRIVILEGES ON DATABASE_NAME.* TO 'DATABASE_USER'@localhost IDENTIFIED BY 'USER_PASSWORD' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    \q

Create a root directory for the website

 mkdir -p /var/www/your-site.com

Do the following on your old virtual server

Create a mysqldump of your database,

mysqldump -u root -p[root_password] [database_name] > /root/database_dump.sql

and copy the database dump file, Nginx configuration and website files over to your new virtual server.

rsync -av -e ssh /var/www/your-site.com/ VPS_IP:/var/www/your-site.com/
rsync -av -e ssh /root/database_dump.sql VPS_IP:/root/
rsync -av -e ssh /etc/nginx/sites-available/your-site.com VPS_IP:/etc/nginx/sites-available/
# moving other data
rsync -av -e ssh /path/to/other/data VPS_IP:/path/to/other/data

Back on your new virtual server:

Import the MySQL dump file:

    mysql -u root -p[root_password] [database_name] < /root/database_dump.sql

Enable your website:

ln -s /etc/nginx/sites-available/your-site.com
/etc/nginx/sites-enabled/your-site.com
/etc/init.d/nginx restart

If you get any errors, check if your php-fpm is configured the same way as on your old server.

Testing

Now that your server is setup it’s time to test if it is working properly. On your local Ubuntu or Mac OS X machine open the /etc/hosts file and add the following line:

    VPS_IP       your-site.com

Open your-site.com in your browser and you should see your website hosted on your new virtual server. If you get an error connecting to the database, check that the MySQL database, username and password are correct. If everything is OK, change the DNS settings for your domain i.e point your domain to your new virtual server IP address.

Redirecting (Optional)

Normally the DNS propagation time may take 12 to 72 hours. During this period some of your visitors will see your website hosted on your old server and others will see your website hosted on your new virtual server. To avoid this issue, you can redirect the traffic from your old virtual server to your new virtual server.

On your old virtual server open the Nginx server block (virtual host) and edit as follows:

    vim /etc/nginx/sites-enabled/your-site.com
    server {
        listen 80;
        server_name www.your-site.com your-site.com;
        location / {
          proxy_pass http://VPS_IP/;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
        }
    }

Don’t forget to restart Nginx for the changes to take effect.

    /etc/init.d/nginx restart

The configuration above will proxy all request from the old virtual server to the new one. This can be especially useful if you frequently update the content.

 

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to do this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Tutorials
How to Install Drupal 7 on CentOS 7 with Nginx, MariaDB and PHP-FPM
Tutorials
How to install Sylius on Debian 8
Tutorials
Install the Sails.js framework on an Ubuntu VPS
There are currently no comments.