Hosting & Moving Multiple WordPress Sites to a LAMP VPS Server

Recently I needed to do a pretty big move for a number of websites. The main reason was I was running an old version of Ubuntu and WordPress was unable to upgrade due to the version of PHP I was running.

As the server was now 3 years old it seemed a better idea to start afresh with a new server.

So that is what I did:

Image: UnSplash

If you need more help with those first steps digital ocean has great instructions for both.

For an added challenge 3 of my sites have SSL certs, so I was going to need to figure out that side of things as well. More to come on that later in the article.

Here is a high overview of the steps taken on old and new servers and some answers I found to a few issues on the way.

Moving the files from server to server

  • Zip up files on old server:
    zip -r backyoursite /home/yoursite/public_html/
  • wget and copy to new:
    wget yoursite.com/backyoursite .zip
  • unzip on new:
    unzip backyoursite -d /var/www/html/yoursite
  • remove on old
    rm backyoursite.zip
  • Sometimes you may end up with the wrong path structure after the unzip. You can use the below to correct:

    mv /var/www/html/yoursite/home/yoursite/public_html/* /var/www/html/yoursite/
    #remove directory even if not empty
    rm -rf home

  • Now change permissions chown on files
    chown -R www-data:www-data yoursite

Database

  • Go into PHPMyAdmin on the old server and do a basic database export to a file.
  • Go to PHPMyAdmin on the new server and create the database and then do the simple database import.
  • Add the database user.
    open wp-config.php to get username and pw
    nano wp-config.php

Apache Settings

  • edit apache config to add virtualhost
    cd /etc/apache2/sites-available
    nano 000-default.conf
    add a virtualhost section for your site by copying what is already there and editing the domain/site names and folders.

    restart apache /etc/init.d/apache2 restart

  • Test by changing your hosts file
  • Once you are happy:
    Switch dns

SSL Cert

If your site had a SSL certificate you will also need to sort that out. If you use LetsEncrypt here are the instructions.

Common Issues

Front page of website works other pages and posts etc don’t work and display 404 errors

This can be solved by logging into your WordPress dashboard, going to settings and resaving your permalinks.

Site just doesn’t load no matter what

Check the apache errors logs for clues.

sudo tail -100 /var/log/apache2/access.log
sudo tail -100 /var/log/apache2/error.log

If you see a plugin showing up in the error log rename the folder inside the plugins directory. That will stop it loading.

e.g mv facebook facebook_old

Summary

Take your time, I moved my sites over several weeks. If you get stuck on something give it a rest for a day or two and then have another shot.

If you get really stuck feel free to reach out, I will try my best to help.

Rob StGeorge
Senior SQL Server Database Administrator residing in Auckland, NZ

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.