I look after a couple of small WordPress sites and have always just gone with a shared hosting plan. But, being a big command line fan I’ve always found it frustrating not having SSH access on any of my servers (never mind root access). I wanted to try out DigitalOcean, as I have heard some good things about them, and it was coming up to renewal time on my current hosting. DigitalOcean are an IaaS provider, similar to AWS. They don’t have nearly the same breadth of services available, but who does? They have all the basics that you would need though: compute instances (droplets), networking, SSD storage, an easy-to-use interface, a simple pricing model, and full root access.
The other thing I like about DigitalOcean are their tutorials. There are loads of these on just about anything you might want to do. Here are a few that I referred to during this process:
Setup Apache virtual hosts (this tutorial is for Ubuntu, so I had to adapt slightly for Centos)
I came across a few little gotchas while migrating the sites and setting this up, so thought I would document them briefly here, in case I need to do this again in another year or so.
I used the WordPress Duplicator plugin to backup and migrate the sites. This works pretty well actually. Install and take a full backup on your existing site. This generates a zip file and an installer.php file. Copy these to to your new site and run the installer from your browser. However, in order to avoid having to do this multiple time, I would suggest doing your DNS and virtual host stuff first – as described below. This is because the Duplicator installer tries to update your WordPress database with the new site URL and location of your files. If you run this while accessing the site from just an IP address then it won’t work when you try to access from your domain name. Wordpress can be quite picky like that. It also tries to update your .htaccess file, which it won’t be able to do until you have configured Apache to allow this.
This was probably the thing that caused me the biggest headache. For any sites not served from your DocumentRoot directory WordPress relies on the .htaccess file to do the necessary redirects. In order to allow this you have to tell Apache to: “AllowOverride All”. This is probably the way it was setup on the shared hosting that I have used before, so I never had to think about it, but it is not the default Apache configuration. In the end it is really quite straight-forward – you just need a virtual host file for each domain you are dealing with, and depending on where you put these you may need to update you main Apache config file (in Centos it is in /etc/httpd/conf/httpd.conf) to include them. The virtual host files should end in “.conf” – I just named them after the domains, e.g. ./mydomain.com.conf
<VirtualHost *:80> ServerAdmin email@example.com ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /var/www/mydomain.com <Directory /var/www/mydomain.com> AllowOverride All Require all granted </Directory> </VirtualHost>
Restart Apache and run the Duplicator installer. Don’t forget to remove the installer files afterwards.