Oct 12, 2021
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.
- Log in to the hPanel. Navigate to Files -> Backups.
- Select Files backups and check the time and date of the latest backup underneath. Click Prepare to download.
- Select Database backups and click Show databases. Find the Database backup with a time and date that matches the Files backup. Click Prepare to Download.
- If there are no backups available, select Generate new backup -> Proceed.
- Once a backup is generated, choose Prepare to download. 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:
- How to Install Nginx, MySQL, PHP v7 (LEMP) stack on CentOS 7
- How to Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
- How to Install Linux, Apache, MySQL, PHP (LAMP) stack on CentOS 7
To change your VPS operating system and pre-installed software, follow the steps below:
- Head to the Servers tab of the hPanel and scroll down until you see Other Settings.
- 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.
- Once the new OS is installed, go to SSH Details to get your VPS IP, port, and username.
- If you don’t know your root password, you can reset it and create a new one by going to the Root password section.
- 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 188.8.131.52, then it should be http://184.108.40.206:10000
- Once you see the login page, enter the SSH credentials.
- In the Webmin Post-Installation Wizard, click Next to set up Virtualmin.
Setting Up Virtualmin
Now let’s break down each of the Virtualmin configuration steps.
- 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.
- Virus Scanning — it’s recommended to enable the ClamAV virus scanner.
- Spam filtering — if you plan to run an Email Server on your VPS, we encourage you to enable SpamAssassin.
- 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.
- MySQL password — enter the password to the database you selected.
- MySQL database size — it’s recommended to opt for the Medium option if you’re not sure which one to choose.
- 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.
- 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:
- Select List Virtual Server menu and click on Create Virtual Server.
- 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.
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.
- Connect to your VPS Server via SSH (See our SSH article if you don’t know how).
- 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:
- 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.
- 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.
Now, we can extract the archive using tar:
tar -xvf u44974900.20191003104635.tar.gz
- 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:
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/
- After this is done, navigate back to public_html that Virtualmin created by typing:
Verify that all files were moved:
You should see something similar to this:
- 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.
- Head over to the Backups section and copy the link address.
- 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
- 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.
- Then, extract the SQL using the gunzip command
- 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:
- Enter the directory where your website files are stored using the cd command.
- 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:
- After confirming that the file is present, you can edit the file using the nano text editor.
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');
- 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.
- 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.
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:
- Backup your website files and database through the hPanel.
- Set up and access the VPS using Virtualmin.
- Download and transfer your website’s files from shared hosting to the VPS.
- Download and import your MySQL databases to the VPS.
- 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!