LinuxPublished on August 29, 20268 min read

How to migrate from shared hosting to a VPS

You can migrate your website from shared hosting to a VPS without downtime if you follow the right order. This guide covers the inventory, transferring files and the database, testing before the DNS switch, then the period when both servers run side by side. The site stays live on shared hosting until the very end.

Moving to a VPS makes sense when you need a specific PHP version, root access or several projects with different settings. The article VPS or shared hosting helps you decide. For a WordPress site, the guide How to install WordPress on a Linux VPS gives a dedicated setup.


Take stock before migrating

A failed migration almost always comes from something forgotten at this stage. Write everything down before you touch a single file.

  • The files. The web folder (often public_html/, www/ or htdocs/), configuration files outside it (.env for example) and files uploaded by visitors (uploads/, storage/).

  • The database. Its name, user and password, from the host's control panel or the application's configuration. Also note the MySQL or MariaDB version.

  • Scheduled tasks (cron jobs) in the host's control panel. They do not follow the site.

  • Mailboxes. They do not migrate with the site. Decide whether to keep them with the current host, without touching the MX records, to move them to an email service, or to run them on the VPS.


Lower the domain's TTL

The TTL sets how long resolvers keep an address in memory. At least a day before the switch, lower the TTL of the domain's A record to 300, which is five minutes. The final switch will then spread quickly.

; Before the migration, usual TTL (often 3600 or 86400)
example.com.  3600  IN  A  198.51.100.10

; Set to 300 at least a day before the switch
example.com.  300   IN  A  198.51.100.10

Then wait at least the length of the old TTL before switching. The TTL is set in the DNS zone, at the domain registrar or the current host. If your domain is with OuiHeberg, open My Services, pick the Domains filter, click the domain, then DNS zone. The pencil on each line of the Records card edits the record.

DNS zone tab of a domain with the Records card and the Add button

The guide How to edit the DNS records of your domain explains each field.


Prepare the VPS

Install and secure the VPS before you copy anything to it.

Finally, create the folder that will hold the site, for example sudo mkdir -p /var/www/example.com. In this guide, 203.0.113.10 stands for the VPS main IP and 198.51.100.10 for the shared host's IP.


Transfer the files

With rsync, if the shared host offers SSH

rsync only copies what has changed, resumes after an interruption and keeps file permissions. Run it from the VPS to pull the files from the shared host.

rsync -avz --progress \
  user@old-host.example.net:/home/user/public_html/ \
  /var/www/example.com/

The options -a (archive, keeps permissions, dates and links), -v (lists files), -z (compresses) and --progress (shows progress) are described in the rsync manual. rsync only accepts one remote machine per command. From your computer, make two passes, from the shared host to the computer, then from the computer to the VPS.

Without SSH access to the shared host

Download the files to your computer with an SFTP client such as FileZilla or Cyberduck, then upload them to the VPS.

# From your computer to the VPS
rsync -avz --progress ./public_html/ \
  root@203.0.113.10:/var/www/example.com/

Set the permissions

sudo chown -R www-data:www-data /var/www/example.com
sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;

Transfer the database

Export it from the shared host

With SSH access, use mysqldump. Without SSH, use the host's phpMyAdmin, Export menu, SQL format.

mysqldump -u site_user -p site_db > site-export.sql

Then copy the file to the VPS.

scp site-export.sql root@203.0.113.10:/root/

Create the database on the VPS and import it

Open the MariaDB SQL shell.

sudo mariadb -u root

Create the database and its user, with your own password.

CREATE DATABASE site_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'site_user'@'localhost' IDENTIFIED BY 'StrongPassword_ChangeMe';
GRANT ALL PRIVILEGES ON site_db.* TO 'site_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Finally, import the export.

mariadb -u site_user -p site_db < /root/site-export.sql

Reconfigure the site on the VPS

The database connection

In the application's configuration file (.env, wp-config.php or config.php depending on the case), set localhost as the database host, then the name, user and password created above.

Absolute paths

On shared hosting, paths often start with /home/user/public_html/. On the VPS, they start with /var/www/example.com/. Fix any that are hard-coded in the configuration.

Addresses stored in the database

Some applications, WordPress included, keep the site address in the database. If it changes, update it. For WordPress, WP-CLI does the job.

sudo -u www-data wp search-replace 'http://old.example.com' 'https://example.com' \
  --path=/var/www/example.com

For other applications, follow the framework's documentation.

The Nginx server block

Create the file /etc/nginx/sites-available/example.com. Here is a base for a PHP site, with the PHP 8.4 socket of Debian 13 (php8.3-fpm.sock on Ubuntu 24.04).

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Moving several sites to the same VPS? The guide Host multiple websites on a VPS with Nginx explains how to keep them apart.


Test the site before the DNS switch

Never switch DNS before you have seen the site running on the VPS. Your computer's hosts file points the domain to the VPS for you only, without touching public DNS. On Linux or macOS, open it with the command below. On Windows, open C:\Windows\System32\drivers\etc\hosts in an editor started as administrator.

sudo nano /etc/hosts

Add this line, with the VPS IP.

203.0.113.10  example.com www.example.com

Your browser now loads the site from the VPS. Check these points.

  • The home page and inner pages display.

  • Forms send their emails.

  • Logging in to the admin area works.

  • Uploaded images and documents open.

  • Redirects (301, 302) are active.

  • The /var/log/nginx/error.log log shows no errors.

sudo tail -f /var/log/nginx/error.log

Remove the line from the hosts file once the tests are done.


Switch DNS and enable HTTPS

Edit the domain's A record so it points to the VPS IP. Do the same for www if it has its own record. If the domain has an AAAA record, put the VPS IPv6 in it or delete it, otherwise some visitors will stay on the old server.

; Before, shared host IP
example.com.  300  IN  A  198.51.100.10

; After, VPS IP
example.com.  300  IN  A  203.0.113.10

With a TTL of 300, most resolvers follow within 5 to 10 minutes. Watch the traffic arrive on the VPS.

sudo tail -f /var/log/nginx/access.log

Certbot can only issue a certificate once the domain points to the VPS. Run it right after the switch. In between, the site is only served over HTTP.

sudo certbot --nginx -d example.com -d www.example.com

The guide Certbot: install a Let's Encrypt SSL certificate on a VPS covers other cases. Once propagation is confirmed, raise the TTL back to a usual value.

example.com.  3600  IN  A  203.0.113.10

Keep the shared hosting active for one to two weeks. You can fetch a forgotten file there, check that emails still arrive if the MX records have not changed, and roll back if something goes wrong. Delete nothing before you have checked everything on the VPS.


Avoid common pitfalls

Emails stay with the old host

Switching the A record does not touch the MX records. Emails keep arriving at the old host. This is often intended during the transition, but make sure it is a choice and not an oversight.

Scheduled tasks no longer run

Cron jobs from the host's panel do not migrate. Recreate them in the VPS crontab, from the list made during the inventory.

crontab -e

Absolute paths remain in the database

Some applications store file paths in the database. Use the application's search and replace feature, or an SQL query like this one, adapted to your tables.

UPDATE wp_options SET option_value = REPLACE(option_value,
  '/home/user/public_html',
  '/var/www/example.com')
WHERE option_value LIKE '%/home/user/public_html%';

The site does not work after the switch

Put the A record back on the shared host's IP. Thanks to the low TTL, the rollback is quick. Look for the cause on the VPS without pressure, then switch again. For an online shop or an application with logged-in users, plan the switch outside peak hours, with a maintenance page.


Need help?

Open a ticket from Tickets › Open a Ticket, or from the Contact support tile at the bottom of the VPS page. In the Related Service field, pick the VPS so the team saves time. You can also ask your question on the OuiHeberg Discord.

Was this article helpful?

125 views
Share this article
Need a Linux VPS?

Root access, your choice of distribution and management from the OuiHeberg client area.

View plans →

Related Articles