The Wild

How to Migrate WordPress from Shared Hosting to a VPS

· 6 min read · Mammals

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Migrating a WordPress site from shared hosting to a VPS (Virtual Private Server) gives you more control, better performance, and room to grow. This guide walks you through the entire process—from preparing your files and database to pointing your domain to the new server—so your site moves with minimal downtime.

What You'll Need

  • Access to your current shared hosting control panel (cPanel, Plesk, or similar).
  • SSH credentials for your VPS (root or a user with sudo privileges).
  • A VPS with a LAMP/LEMP stack installed (Linux, Apache/Nginx, MySQL/MariaDB, PHP). If you haven't set this up yet, do that first.
  • A domain name (you'll update its DNS records).
  • An FTP/SFTP client like FileZilla, or command-line familiarity.
  • A temporary URL or IP address to test your site before switching DNS.

Step-by-Step

  1. Back up your WordPress files. In your shared hosting file manager, navigate to the root folder (often public_html). Select all files and folders, compress them into a .zip or .tar.gz archive, and download it to your computer. Alternatively, use an FTP client to download the entire directory.
  2. Export your WordPress database. Open phpMyAdmin in your shared hosting control panel. Select your WordPress database (usually named something like wp_ or youruser_wp). Click the "Export" tab, choose "Quick" or "Custom" (select "gzip" for compression), and download the SQL file.
  3. Prepare your VPS environment. Log into your VPS via SSH. Ensure your web server (Apache or Nginx), MySQL/MariaDB, and PHP are installed and running. Create a directory for your site, e.g., /var/www/yourdomain.com. Set appropriate permissions: sudo chown -R www-data:www-data /var/www/yourdomain.com (for Apache on Ubuntu/Debian).
  4. Upload your WordPress files to the VPS. Use an SFTP client or SCP to upload the archive you downloaded. Then extract it into the site directory. For example, if you uploaded wp-backup.zip to /tmp, run: sudo unzip /tmp/wp-backup.zip -d /var/www/yourdomain.com.
  5. Create a new database and user on the VPS. Log into MySQL: sudo mysql -u root -p. Run the following commands (replace placeholders):
    CREATE DATABASE wp_db;
    CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password';
    GRANT ALL PRIVILEGES ON wp_db.* TO 'wp_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
  6. Import your database into the new MySQL. Use the command line: mysql -u wp_user -p wp_db < /path/to/your-database.sql. If you downloaded a gzipped file, first decompress it.
  7. Update the wp-config.php file. On your VPS, edit /var/www/yourdomain.com/wp-config.php and change the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST (usually 'localhost') to match the new database credentials.
  8. Update the site URL in the database. If your domain isn't pointing to the VPS yet, you'll need to temporarily set the site URL to the VPS's IP address. Run these SQL commands (replace your_server_ip with your VPS IP):
    UPDATE wp_options SET option_value = 'http://your_server_ip' WHERE option_name = 'siteurl';
    UPDATE wp_options SET option_value = 'http://your_server_ip' WHERE option_name = 'home';
    If your domain is already pointing to the VPS, skip this step.
  9. Configure your web server. Create a virtual host (Apache) or server block (Nginx) for your domain. Point its document root to the WordPress directory. Enable the site and reload the web server. For Apache: sudo a2ensite yourdomain.conf && sudo systemctl reload apache2. For Nginx: sudo ln -s /etc/nginx/sites-available/yourdomain /etc/nginx/sites-enabled/ && sudo systemctl reload nginx.
  10. Test your site on the VPS. If you haven't changed DNS yet, edit your local hosts file to point your domain to the VPS IP temporarily. Or use the IP address directly. Visit the site and check that pages load, images display, and the admin login works.
  11. Update DNS records. Go to your domain registrar (or DNS provider) and change the A record for your domain (and www) from the shared hosting IP to your VPS IP. DNS propagation can take a few hours to 48 hours.
  12. Final cleanup. Once DNS has propagated and you've confirmed the site works, you can cancel your shared hosting account. Before that, keep it active for a few days to catch any issues.

Common Mistakes

  • Forgetting to update wp-config.php: Using old database credentials will cause a connection error.
  • Not updating the site URL: If you skip the URL update, you'll be redirected to the old host.
  • Incorrect file permissions: WordPress needs write access to certain folders (uploads, plugins, themes). Set directories to 755 and files to 644, and ensure the web server owns them.
  • Ignoring PHP version differences: Your shared host may run PHP 7.4 while your VPS runs 8.3. Check for plugin/theme compatibility.
  • Not testing before switching DNS: Skipping the test step can lead to a broken site for visitors.

Tips

  • Use a plugin like UpdraftPlus or Duplicator to simplify backup and migration, but verify the files manually afterward.
  • If your site has a lot of media, consider using rsync to transfer files directly from old to new server to avoid large downloads/uploads.
  • Set up a caching plugin (like W3 Total Cache) after migration to improve performance.
  • Enable SSL (Let's Encrypt) on the VPS before going live to avoid mixed-content issues.
  • Take a snapshot of your VPS after a successful migration—it's a free rollback point.

Troubleshooting

  • Site shows "Error establishing a database connection": Check your wp-config.php credentials, ensure MySQL is running (sudo systemctl status mysql), and verify the database exists.
  • Pages load but styles/images are broken: This usually means the site URL is still pointing to the old domain. Update the wp_options table as shown above, or use a plugin like "Better Search Replace" to update URLs in the database.
  • 404 errors on pages other than the homepage: If you're using Apache, enable mod_rewrite and ensure .htaccess is present. For Nginx, you need to add the WordPress pretty permalink rules to your server block.
  • White screen of death: Check PHP error logs (/var/log/php_errors.log or similar). It's often a plugin/theme incompatibility—disable them by renaming the plugins and themes folders temporarily.
  • Can't log into wp-admin: This is often due to a cached redirect. Clear your browser cache and cookies, or try accessing /wp-login.php directly.
  • DNS not propagating: It can take up to 48 hours. Use a service like whatsmydns.net to check. In the meantime, test using your hosts file.

Frequently Asked Questions

How long does the migration take?

Most of the time is spent on file transfer and DNS propagation. The actual work can be done in 1-2 hours if you're comfortable with the command line.

Will my site experience downtime?

If you follow the steps and test before switching DNS, downtime can be minimal—often just the few minutes it takes for DNS to update.

Do I need to change my domain's nameservers?

No, you only need to update the A record (or AAAA for IPv6) to point to your VPS IP. Nameservers stay the same.

Can I keep my shared hosting as a backup?

Yes, keep it active for a few days after migration to ensure everything works. You can also take a full backup of the VPS for extra safety.

What if my VPS has a different control panel (like Plesk or cPanel)?

The steps are similar—use the panel's file manager and database tools instead of the command line. The core migration steps remain the same.

Is it safe to delete the old hosting account?

Only after you've confirmed the new site works perfectly for at least a few days. Also, keep a local backup of the files and database.