Migrating a website to a VPS: a step-by-step guide
Updated 5 min readBy the DNSPeek team
To move a website to a VPS, first prepare the server: updates, SSH keys, a firewall and the same web stack the site runs on today. Copy the files and database, configure a virtual host for your domain, and test the site on the VPS IP under its real domain before you change DNS. Switch with a short TTL, issue the certificate, and keep email with a dedicated provider rather than on the VPS.
What changes when you leave shared hosting
On shared hosting the provider runs the web server, PHP, the database, email, backups and security updates. On an unmanaged VPS, all of that is now yours. The upside is control and predictable resources; the cost is that nothing is set up until you set it up. Plan the move as two projects: build the server, then move the site onto it.
| Task | Shared hosting | Unmanaged VPS |
|---|---|---|
| Security updates | Host | You (or unattended upgrades) |
| Web server, PHP, database | Preinstalled | You install and tune them |
| Email hosting | Usually included | Better kept at a dedicated provider |
| Backups | Often included | You configure them, ideally off the server |
| Certificates | Automatic | Certbot or a similar ACME client |
Prepare the server
Start from a supported Linux release. The commands below are for Ubuntu or Debian; adapt package names for other distributions.
# Updates and a non-root user with sudo
apt update && apt upgrade -y
adduser deploy && usermod -aG sudo deploy
# Firewall: SSH, HTTP and HTTPS only
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
# Automatic security updates
apt install -y unattended-upgradesLog in with an SSH key, then disable password logins for SSH. Install the stack the site needs, for example nginx or Apache, PHP-FPM with the same version and extensions as the old host, and MySQL or MariaDB. Matching the PHP version avoids surprises; upgrade it later as a separate step.
Move the site step by step
Step 1: Lower the TTL
Set the A records to a 300-second TTL a day before the switch. Check the current value with the TTL checker.
Step 2: Secure the VPS and install the stack
Apply updates, create a sudo user, enable SSH keys and a firewall, then install the web server, PHP and database versions the site needs.
Step 3: Copy the files
Copy the site with
rsync -avzover SSH, or download an archive from the old host and upload it. Set ownership to the web server user.Step 4: Import the database
Export it on the old host, create a database and user on the VPS, import the dump and update the application’s configuration with the new credentials.
Step 5: Configure the virtual host
Add a server block for the domain and www, translate any .htaccess rules, and reload the web server.
Step 6: Test on the VPS IP before DNS
Create a preview link with the domain and the VPS IP, and use HTTP only or Skip verification mode until a certificate is installed. Click through, submit forms, sign in.
Step 7: Run a QA report
Crawl the preview with a QA report to catch default web server pages, 502 errors from PHP-FPM, missing rewrite rules and PHP errors.
Step 8: Switch DNS and issue the certificate
Do a final file and database sync, point the A records at the VPS, then issue the certificate and watch propagation with the DNS propagation checker.
Configure the virtual host
The web server picks the site by the domain name in the request. Configure a server block for both example.com and www.example.com:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
}If the site relied on .htaccess rules on the old host, translate them for nginx: pretty URLs, redirects and access restrictions do not carry over on their own. Adjust the PHP-FPM socket path to the version you installed. Test the configuration with nginx -t before every reload, and check the PHP-FPM pool settings: the default number of worker processes is small, and a busy site that runs out of workers answers with 502 or 504 errors.
HTTPS before the switch
Let’s Encrypt’s usual HTTP challenge only works once the domain points at the VPS. You have three options: issue the certificate right after the switch (a few minutes over plain HTTP or a self-signed certificate), use the DNS challenge, which works before the switch if your DNS provider has an API, or copy the existing certificate from the old host.
For testing, a fresh VPS without any certificate works with a DNSPeek preview in HTTP only mode: visitors still open the preview over HTTPS, and DNSPeek talks plain HTTP to the server. Make the application trust the proxy’s HTTPS first, or a forced-HTTPS redirect will loop. The docs show the PHP and nginx settings: Origin without SSL.
Email: don’t move it onto the VPS
If the old shared host also handled your email, the move is a good moment to separate them. Running a mail server well (spam filtering, reputation, DKIM, blocklists) is a job of its own, and many cloud providers block outbound port 25 by default. Move mailboxes to a dedicated email provider, update MX, SPF, DKIM and DMARC, and let the website send transactional mail through an authenticated SMTP service. Verify the records with the MX lookup, SPF checker and DMARC checker.
After the switch
- Issue or verify the certificate and check it with the SSL checker.
- Set up backups that leave the server: database dumps and files, to object storage or another machine, and test a restore.
- Add basic monitoring: uptime checks, disk space and certificate expiry.
- Recreate cron jobs from the old host.
- Follow the post-move checklist.
VPS migration checklist
VPS
- Updates applied, unattended upgrades on
- Non-root sudo user, SSH keys, password login off
- Firewall allows only SSH, HTTP and HTTPS
- Same PHP version and extensions as the old host
- Files copied, ownership and permissions set
- Database imported, app configuration updated
- Virtual host for domain and www; rewrite rules translated
- Site tested on the VPS IP with a preview link
- QA report clean
- Email moved to a dedicated provider; MX, SPF, DKIM, DMARC set
- Final sync, DNS switched, certificate issued
- Off-server backups and a tested restore
- Uptime and disk monitoring in place
Frequently asked questions
Is a VPS faster than shared hosting?
Often, because the CPU and memory are reserved for you rather than shared with many other sites. Speed still depends on configuration: PHP-FPM settings, caching and the database matter as much as the hardware.
Can I get an SSL certificate on a VPS before changing DNS?
Yes, with a DNS challenge if your DNS provider supports it, or by copying the existing certificate from the old host. The standard HTTP challenge only works once the domain points at the VPS.
How do I test my site on a VPS before pointing the domain to it?
Request the site from the VPS IP under its real domain. A preview link does this in any browser and can be shared; a hosts file entry does it on your own computer. Opening the bare IP usually shows the default web server page.
Should I host email on my VPS?
Usually not. Mail servers need ongoing care for spam filtering, reputation and blocklists, and many cloud providers block outgoing port 25. A dedicated email provider plus an SMTP service for the website is simpler and more reliable.
What is the most common mistake when moving to a VPS?
Forgetting the work the old host did silently: backups, security updates, email and cron jobs. List everything the old host provided before the move and decide who handles each part on the VPS.