Setting up a LAMP stack on DigitalOcean

DigitalOcean logo

I’ve hosted most of my sites on a DreamHost shared server since 2005. It has always been easy to use and well maintained. But after DreamHost increased prices in March, I decided it was time to look at what else is available.

DigitalOcean has been on my radar for quite a while due to its reputation and inexpensive cloud servers (as little as $5 per month). I can run 2 or 3 cloud servers on DigitalOcean for about the same price as my DreamHost subscription. The downside of course is that the cloud servers are unmanaged, which means potentially more work for me to maintain. I have some experience running an unmanaged Rackspace server in my previous job, so I decided to go ahead and give it a try.

Setting up the server

The initial sever setup was pretty straightforward. I used the DigitalOcean dashboard to create a new server (called a Droplet), choosing “LAMP on Ubuntu” from the marketplace, which came pre-configured with most of what I needed to run my PHP sites. I’ve heard the WordPress image is pretty good (and would probably be much easier for setting up a WordPress site), but I have a mixture of PHP sites, which is why I went for a basic LAMP stack.

Be sure to check the “Monitoring” box under “Select additional options” to install the DigitalOcean metrics agent if you want some additional graphs on your DigitalOcean dashboard. I didn’t do this during the Droplet setup, so I just had to install the package myself to get the extra monitoring.

Once the Droplet was created, DigitalOcean provided a nice set of “get started instructions” to read, with general information such as where to find my server IP address, the MySQL root password, and the location of the web root. The instructions included links for How To Set Up Apache Virtual Hosts on Ubuntu and How To Secure Apache with Let’s Encrypt on Ubuntu, which uses a pre-installed certbot package that makes generating SSL certificates easy.

Next, I went through the Initial Server Setup with Ubuntu guide, which I used to set up a new user with admin privileges and external access (as it’s generally discouraged to use the root account regularly). I skipped the firewall steps, which were automatically set up with the LAMP Droplet image.

That’s all I needed for the basic server setup. I then added the Apache virtual hosts for my websites, imported my databases, and I was good to go.

Installing updates

One of my primary concerns with running an unmanaged server is keeping it updated. After running for a week, there were already quite a few updates to install.

Package updates are pretty easy to install and can be handled by a one-line command I found on a DigitalOcean community page:

sudo apt-get update && sudo apt-get dist-upgrade

There’s a good answer on Ask Ubuntu explaining exactly what all of this does.

For upgrading to future releases of Ubuntu, it’s a much different story. There is a tutorial on DigitalOcean for [upgrading Ubuntu]( "How To Upgrade to Ubuntu 20.04 Focal Fossa”), but at the beginning of the article, they recommend migrating data to a new server rather than upgrading an existing one. Fortunately, if you choose an Ubuntu LTS release, it should be years before the server will need an upgrade.

Additional thoughts and concerns

  • Performance: I wasn’t sure how well an inexpensive cloud server would run, but so far, it feels like a performance upgrade over the shared server.
  • Downtime: DigitalOcean promises 99.99% uptime, but I’ve already received a few downtime notices from Jetpack for my WordPress site. This is something that would happen on DreamHost from time to time as well. I did have one morning where all my sites on the new server were unresponsive for a few minutes. Looking at the performance graph showed a huge spike across the board during that time, so it will be something to keep an eye on.
  • Backups: DigitalOcean has an option for a weekly Droplet backup for $1 more per month, but that’s all they offer. I would like to have all my databases and files backed up a bit more regularly, so I will probably end up writing shell scripts to handle that.
  • SSL certificate renewal: Let’s Encrypt certificates are only valid for ninety days and then need to be renewed, something DreamHost handled for me. DigitalOcean says the certbot package should automatically take care of the renewal when needed, but it will be interesting to see what happens in a few months.

What’s next

I would like to get a cron job set up to handle the server updates. I don’t want to be regularly installing updates and restarting the server manually.

I’ve also considering installing phpMyAdmin, because it’s something I’ve always used in the past to manage my databases. On the other hand, I know it’s not needed, and I’m kind of enjoying figuring out how to get by without it.

Running a server on DigitalOcean is going to be a bit more work than a shared server on DreamHost, but it doesn’t look to be too difficult. Also, there’s a part of me that enjoys doing this sort of work and figuring things out. We’ll see how I feel if/when things start to break. But for now, things are running smoothly, and my websites feel a bit faster on the new server.