How to migrate a website from shared hosting to VPS

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

Why do you need VPS Hosting

Before we go into the steps, we’d like to explain why you might want to move from shared hosting to . There are several reasons to do it.

First of all, you will be able to get more resources from the server. VPS offers more CPU, RAM and storage compared to shared hosting. This way, your site can handle more traffic and store more data with virtually no problems.

Second, with a VPS you have a dedicated partition of a server to yourself. That means if other users are faced with increased traffic or a security issue, your website won’t be affected.

Last but not least, you will have full control over your machine. For example, you get full root access, which allows you to modify your system more freely. In addition, the VPS offers you a dedicated IP, as well as greater stability and performance.

Although having a private server can be more expensive and technical, it is the perfect option if you have a fast growing website.

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

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

Step 1 – Create a backup of your website

When making any changes to a website, it is necessary to make a backup to avoid data loss in case something goes wrong. Also, making a backup will make it easier to transfer files and databases from one server to another.

Here we explain how to do it through the hPanel.

  1. Log in to the hPanel. In the tab of hostinggo to Records> Backups.
  2. You will see the File Backups and Database Backups sections. In both sections, find your latest file and database backups and tap prepare to download.
  3. If there is none, click the button Generate new backup.
  4. Once a backup has been generated, click prepare to download. Wait a few seconds while the download prepares.

Now that the backup files are ready, let’s proceed to VPS.

Step 2 – Set up a VPS server

We recommend choosing a template that has LAMP Y Webmin/Virtualmin pre-installed. You can also use a VPS server with Cyberpanel, which will allow you easier management.

See also  How to use the Time command in Linux

You can also configure your own stack (no GUI). We have these helpful tutorials on how to install different stacks on various UNIX-based operating systems:

To change your VPS’s operating system and pre-installed software, follow these steps:

  1. Go to the tab servers from 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. Please note that the new system may take a few minutes to boot up.

Access to Webmin / Virtualmin

  1. Once the new operating system is installed, go to SSH Details To obtain the IP of the VPSthe port and the Username.
  2. If you don’t know your root password, you can reset it and create a new one in the section root password.
  3. To access Webmin / Virtualmin, add https:// before ssh ip address Y: 10000 port at the end. If your address is 31.220.62.131 then it should behttp://31.220.62.131:10000.
  4. Once you see the login page, enter your SSH credentials.
  5. In the Webmin Post-Installation Wizardclick Next to configure virtualmin.

Configure Virtualmin

We will see each installation step one by one:

  1. Memory:
    • Load Virtualmin libraries previously? It is recommended to select Nope since since most of the process will be done via SSH.
    • doRun email domain lookup on server? If you want to run an Email Server on your VPS, choose Yes. Note that this option uses more RAM.
  2. virus scan: It is recommended Activate the virus scanner.
  3. Spam filtering: If you plan to run a email server on your VPS, we recommend enable .
  4. Database servers: select the database you want to use. A data base mysql is the best option for most cases. On the other hand, you can deactivate the database server PostgreSQL.
  5. MySQL password: Enter the password for the database you selected.
  6. MySQL database size: It is recommended to select the option Half if you are not sure which one to choose.
  7. DNS Zones: Since we are going to point the domain name to the VPS server through the A record, we don’t need private nameservers for now. Therefore, select Skip resolvability check.
  8. Passwords: if you want everything to be more secure, select the option Only store hashed passwordsas it will encrypt all stored passwords.

Once the setup process is complete, click the button Recheck and update settings to check if the server has been configured correctly.

Creating a Virtual Private Server

Now you will need to create a new user, MySQL database, and a directory for your website. Here are the steps to do it with Virtualmin:

See also  What is GitHub and How to Use it?

1. Go to List Virtual Server -> Create Virtual Server.
2. Enter the domain name and administration password and press the button Create server. This will create a simple server that is enough to host a website.

Step 3 – Migrate your website files to VPS

Now that you have set up the VPS server, you can migrate the website files and databases one by one from the shared hosting server.

We will use the wget command to download the backup files that we created in step 1.

  1. Connect to your VPS server through a .
  2. Access the working directory where you will store your website files. Since Virtualmin automatically creates a directory based on the domain name, the command should look like this:
    cd /home/-dev-9/public_html/
    remember to replace -dev-9 with the correct domain name.
  3. Go back to hPanel -> Backups and copy the download link of your backup file. To do so, right click on the button Discharge and choose Copy the url.
  4. Use the wget command to download the backup to the VPS. If you can’t paste the link into the SSH client, paste it into a text editor first. This is an example of what the command will look like:
    wget http://srv167.main-hosting.eu:8080/download-backup/fe26ee2e4159db037c3106c37fa3ffb5b2072662/backup-file-name.tar.gz
  5. Then, extract the archive using the :
    tar -xvf backup-file-name.tar.gz
    In this command and the previous one, substitute backup-file-name.tar.gz by the name of the corresponding file.
  6. We have created a new folder public_html. We will move its content to the folder public_html original. Start by accessing the folder public_html extracted using the command CD:
    cd database-name/public_html/
    remember to replace database-name.
  7. Then move all the files to the folder public_html created by Virtualmin using the command mv:
    mv -v /home/-dev-9/public_html/database-name/public_html/* /home/-dev-9/public_html/
  8. go back to directory public_html created by Virtualmin using the command CD:
    cd /home/-dev-9/public_html/
  9. Use the command ls to verify that the folder contains all the moved files. You should see something similar to this:
  10. Virtualmin creates a user and a group based on the domain name. Change the ownership of files and folders to match Virtualmin credentials using the :

chown -dev-9:-dev-9 -R *

Step 4 – Transfer Database Files to VPS Server

We will use the command wget to download the backup files of your hosting account to the VPS as in the previous step.

Remember that the MySQL database was already created during the configuration of the VPS. Therefore, there is no need to create additional databases.

Check MySQL database name and password

In order to import the database backup and complete the transfer process we first need to find our new database name, username and password. The database name can be found in the control panel of virtualminin the Edit Databases section.

See also  Top 7 WordPress Security Plugins to Keep Your Site Secure

The MySQL database username and password are located in the same section, on the Password tab.

In our example, our MySQL details are:

  • MySQL database name (MySQL Database Name) – hostinger_dev_9
  • MySQL username (MySQL Username) – -dev-9

Download and import MySQL backup

Once you have the MySQL database name, import the MySQL backup by following these steps:

  1. Go to the section Backups from your shared hosting and copy the download link.
  2. In the VPS control panel, create a new directory called “sql_backup” and enter it using the following command:
    mkdir sql_backup && cd sql_backup
  3. Once inside that directory, use the command wget to download the file from the hosting backup and save it to the new server.
    wget http://srv167.main-hosting.eu:8080/download-backup/60a7e64afb1a769b1de4f2139aa0a27c2c2ecb01/backup-file-name.sql.gz
  4. Extract the compressed file using the command gunzip:
    gunzip backup-file-name.sql.gz
  5. You will get a file with the same name in format .sql. Move it to the new database using the following command. Remember to replace the MySQL database file name with your own.

mysql -u root -p hostinger_dev_9 < MySQL-database-name.sql

Step 5 – Make the last changes

Although we have transferred all the files and databases, the VPS migration process is not ready yet.

If the message appears Error establishing a database connectionyou will have to edit the file wp-config.php and update it with the new data from the MySQL database. This is how you do it:

  1. Enter the directory where your website files are stored using the command CD.
    cd /home/-dev-9/public_html/
  2. There you will see all the files present in the current directory. Check if the file wp-config.php is present in the directory using the command ls.
  3. After confirming that the file is present, you can edit it with the Nano text editor using this command:
    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’, ‘database-name’);
    /* mysql database username /
    define(‘DB_USER’, ‘username’);
    /*…
Loading Facebook Comments ...
Loading Disqus Comments ...