VPS

How to Migrate Website from Shared hosting to VPS

Are you planning to upgrade from shared hosting to VPS? If so, you are in the right place! In this tutorial, we will guide you through the process of moving your WordPress site from shared hosting to VPS for better performance and security.

Why You Need VPS Hosting

Before we move on to the steps, we would like to explain why you might want to upgrade from shared hosting to a VPS. There are several reasons to do that.

First of all, you can get more server resources. VPS offers more CPU, RAM, and storage compared to shared hosting. That way, your site can handle higher traffic and store more data with little to no issues.

Secondly, with a VPS, you have a dedicated partition of a server to yourself. That means if other users face a traffic surge or a security problem, your website won’t be affected.

Last but not least, you have total control over your machine. For instance, you gain full root access, which allows you to modify your system more freely. Also, VPS gives you a dedicated IP, better stability, and performance.

While owning a private server can be more pricey and technical, it is the perfect option if you have a quickly growing website.

Now for this tutorial to work, you will need access to your shared hosting account, VPS, and domain’s management panel. If you don’t have a VPS yet, you can take a look at our reliable and affordable VPS plans.

Without further ado, here are the steps to migrate from shared hosting to VPS.

Step 1 — Creating a Site Backup

When making any changes to a website, a backup is necessary to prevent any data loss in case anything goes wrong. Plus, backing up will also make it easier to transfer files and databases from one server to another.

Here is how to do it through Hostinger’s hPanel.

  1. Login to the hPanel. On the Hosting tab, navigate to Files -> Backup.
  2. You’ll see a list of recent backups that are sorted by type and date. Look for your latest MySQL and website backups and hit Prepare Backup.
    Backup list on Hostinger's hPanel
  3. If there’s none, scroll down to find the Generate a new backup button.
  4. Once a backup is generated, choose Prepare Backup. After a few seconds, it will turn into a Download button. Leave it that way since you only need to get the link later on.

Now that the backup archives are ready let’s proceed to set up a VPS server.

Step 2 — Setting Up a VPS Server

We recommend choosing a template that has LAMP stack and Webmin/Virtualmin pre-installed. It will allow for easier management of the server.

Alternatively, you can set up your own stack (without a GUI). We have several useful tutorials on how to install different stacks on various UNIX-based OS:

To change your VPS operating system and pre-installed software, follow the steps below:

  1. Head to the Servers tab of the hPanel and scroll down until you see Other Settings.
  2. Change the operating system to  Ubuntu 18.04 64bit with Webmin/Virtualmin/LAMP and click Save Changes. Keep in mind that the new system might take a few minutes to start.
    VPS Settings on Hostinger's hPanel

Accessing Webmin/Virtualmin

  1. Once the new OS is installed, go to SSH Details to get your VPS IP, port, and username.
  2. If you don’t know your root password, you can reset it and create a new one by going to the Root password section.
  3. To access Webmin/Virtualmin, you should add http:// before your SSH IP address and the :10000 port at the end of it. If your address is 31.220.62.131, then it should be http://31.220.62.131:10000
  4. Once you see the login page, enter the SSH credentials.
  5. In the Webmin Post-Installation Wizard, click Next to set up Virtualmin.
    Virtualmin Post-Installation wizard

Setting Up Virtualmin

Now let’s break down each of the Virtualmin configuration steps.

  1. Memory
    • Preload Virtualmin libraries? — it’s recommended to choose No as most of the process is done through SSH.
    • Run email domain lookup server? — if you want to run an Email Server on your VPS, then choose Yes. Keep in mind that this feature uses more RAM.
  2. Virus Scanning it’s recommended to enable the ClamAV virus scanner.
  3. Spam filtering  if you plan to run an Email Server on your VPS, we encourage you to enable SpamAssassin.
  4. Database servers – this the selection of the database you want to use. A MySQL database is your best bet for most cases. On the other hand, you can disable the PostgreSQL database server.
  5. MySQL password — enter the password to the database you selected.
  6. MySQL database size  it’s recommended to opt for the Medium option if you’re not sure which one to choose.
  7. DNS Zones — as we will point the domain name to the VPS server via the A record, we don’t need private nameservers for now. Thus, select Skip check for resolvability.
  8. Passwords — if you want everything to be more secure, select the Only store hashed passwords option as it will encrypt all of your stored passwords.

That’s it. The Virtualmin configuration is complete! Click the Re-check and refresh the configuration button to test whether the server has been set up properly. If everything is working as intended, then you’re good to go!

Step 2.3 – Creating a Virtual Server

It is time to create a new user, MySQL database, and a directory for our website. It can be done all at once using Virtualmin:

  1. Select List Virtual Server menu and click on Create Virtual Server.
  2. After that, enter your domain name and administration password and press the Create Server button. This will create a simple server which is enough to host a website.
    Create Virtual Server interface on Virtualmin

Step 3 – Transferring Website Files to the VPS

Now that we have set up the VPS server, we will transfer our website files and databases one by one from our shared hosting server.

We’ll be using the wget command to download backup archives that we have created in Step 1.

  1. Connect to your VPS Server via SSH (See our SSH article if you don’t know how).
  2. Access the working directory where you will store your website’s files. Since Virtualmin automatically creates a directory based on the domain name, the example should look like this:
    cd /home/hostinger-dev-9/public_html/
  3. Head back to Hostinger hPanel -> Backups and copy the download link of your backup archives. You can right-click on the Download button and choose Copy link address.
  4. Use the following command to download the backup to the VPS (remember to change the link address). In case the link can’t be pasted in the SSH client, paste it in a text editor first.
    wget http://srv167.main-hosting.eu:8080/download-backup/fe26ee2e4159db037c3106c37fa3ffb5b2072662/u499474900.20191003104635.tar.gz

    Now, we can extract the archive using tar:

    tar -xvf u44974900.20191003104635.tar.gz
  5. It will create a new public_html folder. What we need to do is move all the files in that folder to the original public_html directory. First, we should access the extracted public_html folder:
    cd u499474900/public_html/

    Then, move all files to the public_html folder created by Virtualmin:

    mv -v /home/hostinger-dev-9/public_html/u499474900/public_html/* /home/hostinger-dev-9/public_html/
  6. After this is done, navigate back to public_html that Virtualmin created by typing:
    cd /home/hostinger-dev-9/public_html/

    Verify that all files were moved:

    ls

    You should see something similar to this:
    public_html content listed on a terminal

  7. Next, we need to change the ownership of the files and folders to match the one from Virtualmin. Just like a directory, Virtualmin creates a user and a group based on the domain name. Therefore, our example command should be as follows:
    chown hostinger-dev-9:hostinger-dev-9 -R *

Step 4 – Transferring Database files to the VPS

After moving the website files, the next step is to transfer our database. Just like with files, we’ll use the wget command to download the database backup from your shared hosting account to the VPS.

Remember, a MySQL database was already created during the Virtual Server creation. Therefore, you don’t need to create additional databases.

Checking MySQL Database Name and Password

To transfer the MySQL database backup, we need to find our newly created database’s name, username, and password. They can be found on the Virtualmin control panel -> Edit Databases section.

In this example, our MySQL details are:

  • MySQL Database Name – hostinger_dev_9
  • MySQL Username – hostinger-dev-9

Downloading and Importing the MySQL Backup

Once you know your MySQL database name, you can proceed with importing the MySQL backup.

  1. Head over to the Backups section and copy the link address.
  2. On our VPS, we will create a new directory and enter it. We will store our MySQL backup archive in it.
    mkdir sql_backup && cd sql_backup
  3. Once we are inside that directory, use the wget command to download the file from the hosting backup and save it on your VPS server.
    wget http://srv167.main-hosting.eu:8080/download-backup/60a7e64afb1a769b1de4f2139aa0a27c2c2ecb01/u499474900_6KMkK.20191003104635.sql.gz
  4. Then, extract the SQL using the gunzip command
    gunzip u694443746_6KMkK.20191003104635.sql.gz
  5. You will now get a file with the same name in .sql format. Move it to our database using the below command. Remember to change the name of the MySQL database archive to your own.
    mysql -u root -p hostinger_dev_9 < u694443746_6KMkK.20191003104635.sql

Step 5 – Making Some Final Changes

Although you have transferred your website’s files and MySQL databases from shared hosting to a VPS, your WordPress site will not work correctly just yet. You might get the Error establishing a database connection message.

To fix this, you will need to edit the wp-config.php file and update it with the new MySQL database details. This is how you do it:

  1. Enter the directory where your website files are stored using the cd command.
    cd /home/hostinger-dev-9/public_html/
  2. Once you are inside the directory, we will see all the files present in the current folder. Let’s check if the wp-config.php file is present in the directory by using the list command:
    ls
    wp-config.php file highlighted on a terminal window
  3. After confirming that the file is present, you can edit the file using the nano text editor.
    nano wp-config.php

    Scroll down until you find these lines:

    // ** MySQL settings – You can get this info from your web host ** //
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'u499474900_k6aUT');
    
    /** MySQL database username */
    define('DB_USER', 'u499474900_iRhfq');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'TqgzW0Pwy9');
    
    /** MySQL hostname */
    define('DB_HOST', 'mysql');
  4. Now enter your database details in these fields:
    • DB_NAME – MySQL database name.
    • DB_USER – MySQL username.
    • DB_PASSWORD – MySQL password.
    • DB_HOST – Enter localhost here since our MySQL database is on the same server.
  5. Once you have made the changes, press CTRL + X and then Y to confirm.

The last step would be to point the domain name to the VPS server from the shared hosting server.  The easiest way to do this is to update A record.

Our domain name resolves to Hostinger’s nameservers, so you can set the A record by going to hPanel -> DNS Editor. Fill in your VPS IP address as the A record and press the Save Changes button.

Note: It can take up to 24 hours for DNS to fully propagate worldwide.

You might want to read the more detailed steps on how to point a domain name to a VPS.

Conclusion

A VPS can offer users better performance and security compared to shared hosting plans. That’s why many people want to upgrade when they need more resources and control over their website.

In this article, you have learned how to migrate from shared hosting to a VPS.  There are five big steps to complete such a task. Let’s overview them:

  1. Backup your website files and database through the hPanel.
  2. Set up and access the VPS using Virtualmin.
  3. Download and transfer your website’s files from shared hosting to the VPS.
  4. Download and import your MySQL databases to the VPS.
  5. Make some final changes to the MySQL databases and point your domain name to the VPS.

Good luck, and be sure to leave a comment if you have any questions!

About the author

Kushan

Kushan is a Linux geek who worked on countless web development projects. He's well seasoned in handling both the back-end and the front-end. When he has free time, Kushan likes to hike and enjoy the beauty of nature.

2 Comments

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in VPS
How to Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
How to Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

Close