How to migrate website from shared hosting to VPS hosting


Here I will guide you how to migrate existing website from shared hosting to VPS hosting. I will talk about mainly PHP based website, for example, WordPress that has MySQL database for storing the information and runs on Apache web server. But this website may be based on any technology with any database as its persistent storage. The same idea may be applicable to websites built on other technologies.

You want to migrate from shared to VPS server hosting when you see a potential growth in number of visitors and your shared hosting server is unable to handle such a huge visitors.

Your hosting provider may also alert you about the limitations of resources usages. Such resources may be CPU, RAM, Bandwidth of the hosting server.

You might have also noticed that sometimes your site responds with http status code 50x, where x is the integer value depends on the server how it is implemented.

This guide is not about to tell any automatic process but we will configure the required things manually one by one.

I won’t explain here what is shared hosting and what is VPS hosting but you can always find a good write up by searching in Google.


In order to setup your existing PHP based website into new VPS server, you need to have the required softwares installed in your Linux (CentOS 7) based VPS server.

In addition to the above requirement you need to have the following backups:

Login to VPS Server

First step is to login to your VPS server using PuTTY, a windows based client for connecting to the remote server through SSH terminal.

For login to remote server you may read how to login to remote Linux server.

Restore MySQL Database

The next step is to create database, database user, import and restore data into MySQL (MariaDB) server under new VPS hosting.

Related Posts:

Let’s say your database name is roytuts_db and database user is roytuts.

First you need to login to MySQL server using the root user which you created during MySQL (MariaDB) server installation.

To login to your MySQL use the below command:

$ sudo mysql -u root -p

The above command will prompt for your user account’s password followed by MySQL user root‘s password.

Once you successfully logged in to MySQL server you will see below welcome screen:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 62204
Server version: 10.3.18-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Your next task is to create database and user for database. To create database use below command:

MariaDB [(None)]> CREATE DATABASE roytuts_db;

You will get success message as Query Ok.

Now you need to create user for your new database using the following command:

MariaDB [(None)]> CREATE USER 'roytuts'@'localhost' IDENTIFIED BY 'password';

In the above command, as said previously, roytuts is the username and password is the password for your database user. Remember to replace those values with your own values.

Now you need to grant all privileges to the user to perform all kind of operations on your database. To do so use below:

MariaDB [(None)]> GRANT ALL PRIVILEGES ON * . * TO 'roytuts_db'@'localhost';

Now you need to flush the privileges so that changes take place without any issue. Use below command:


If you want to check if your database has been created or not using the below command:

MariaDB [(None)]> show databases;

You may find other databases along with your own database in the list.

You can also verify your user has been created or not using the below command:

MariaDB [(None)]> SELECT User, Host FROM mysql.user;

The list returns your database user along with other users such as root.

Now you can check the tutorial how to restore your database using command line tool to import your database file.

Restore Website Files

make sure you have the archive zip file of your website files. You need to first upload your archive zip file into your user’s home directory using FileZilla or any FTP client. Let’s say your website’s archive backup file name is

Now we need to copy the file into web root directory location – /var/www/html.

So connect to the remote server using PuTTY through SSH terminal. By default once connected you will be in your home directory and in the home directory you have file.

To copy the file use the below command:

$ sudo cp /var/www/html/

Now you need to extract the archive zip file under /var/www/html directory.

Note if you extract this zip file under any sub-directory of web root directory then you have to change the configuration for your virtual host.

Now go to the web root directory using below command:

$ cd /var/www/html

Extract the file under web root directory – /var/www/html using the below command:

$ sudo unzip

Once all files are extracted under web root directory you can verify whether you are able to access your site or not by typing the website URL or typing the VPS server’s public IP address into the browser.

if you are unable to access your website then consider configuring virtual host.

Configure Virtual Host

You need to configure virtual host.

Edit the Apache web server configuration file – httpd.conf. Use below command to edit:

$ sudo vi /etc/httpd/conf/httpd.conf

Add the following content into it. Press i from your keyboard to enter INSERT mode otherwise you won’t be able to write or change anything in the file.

Write the below content into it. Remember to change the with your domain.

<VirtualHost *:80>
    DocumentRoot /var/www/html
    ErrorLog /var/www/html/error_log
    CustomLog /var/www/html/requests_log combined

The above content is self-explanatory.

If you are using .htaccess file in your website then you have to change the AllowOverride from None to All for directory /var/www/html.

<Directory /var/www/html>
 # AllowOverride controls what directives may be placed in .htaccess files.
 # It can be "All", "None", or any combination of the keywords:
 # Options FileInfo AuthConfig Limit
 AllowOverride All

Make sure you either stop and start or restart the httpd service to reflect your changes.

To stop httpd service:

$ sudo systemctl stop httpd.service

To start httpd service:

$ sudo systemctl start httpd.service

To restart httpd service:

$ sudo systemctl restart httpd.service

To test your website is working or not, you can either type the server’s public IP address or domain name ( into the browser. If everything is fine you should see your site’s home page on the browser.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *