WordPress Setup Digital Ocean

Digital Ocean Account Setup

To work with Digital Ocean you need an account. It can be one run by developer, but preferably one client runs and to which he invites you as a developer and or DevOps. So you need the following for starters

  • Setup of account by client with DO
  • Team Setup with access for developer

Droplet Setup

Droplet’s setup is relatively easy using the Digital Ocean’s interface. You need to choose the proper droplet, your preferred region, Droplet size and Droplet base OS.

  • Droplet Size – At least 1 GB
  • Region Choice
  • Ubuntu 18.0.4 Setup with SSH keys attached
  • FQDN domain name connected to ip Droplet
  • Domain name must be directed to Digital Ocean DNS Server from Domain Service Provider
  • Domain at Digital Ocean must be directed with A Record to Droplet’s IP
  • Digital Ocean LEMP with WordPress

WordPress Setup Digital Ocean

Once you have taken care of the Droplet and Domain setup we move onto the actual guide for setting up a WordPress LEMP. This guide will be your base. It explains all and refers to requirements needed like:

  • initial Ubuntu 18.0.4 Server Setup
  • LEMP Setup
  • Let’s Encrypt SSL Setup

before moving onto setting things up like the

  • actual database installation,
  • PHP extensions,
  • WordPress Download
  • WordPress Config Tweaks
  • WordPress GUI Installation

Digital Ocean Initial Server Setup

Digital Ocean has a great guide mentioning where need be all extra steps to take to setup a basic Ubuntu Server to get going

It will guide you through setting up a server with

  • Sudo User,
  • basic firewall,
  • external access

Digital Ocean LEMP Setup

For the LEMP setup there is another great guide. It will go through all the necessary steps to set up a LEMP with:

  • Nginx webserver,
  • MySQL Database server,
  • PHP-FPM PHP Parser

on your Ubuntu Linux Droplet.

SSL Setup

Let’s Encrypt SSL Setup to get a free SSL certificate is not hard anymore these days and DO also gots your back here with this guide. It explains the DNS needs to set you up with LE SSL using Certbot.

Database Setup

MySQL Database installation on MYSQL Server is explained in the base tutorial. It basically tells you how to add the database from the command line with needed privileges and such.

PHP Extensions

Installing the necessary PHP Extensions is also explained in the base guide just like the database setup. Just follow it, install the necessary extensions with apt:

  • sudo apt update
  • sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip

See guide for all the details

WordPress Installation

Downloading of the needed WordPress files to run the WordPress CMS is what you need to do here. Also explained in base guide as well as on WordPress. We can use curl for this step as you will see in the guide.

WordPress Configuration

Configuring the WordPress configuration file to work with the set up database, necessary constants for security like the AUTH_KEY.

Installation via Interface

Installation of WordPress following the instructions in the browser. Explained in base guide as well as on WordPress and actually pretty self explanatory.

 

Digital Ocean Volume for WordPress Media

Adding Digital Ocean Volume for WordPress Media can be very useful. Especially if you have a lot of images and or other media and need a cheap way to store them. Block Storage at Digital Ocean is fast and easy to work with. It allows you to get a cheap Droplet and add cheap storage.

We already wrote about Setting up Trellis on Digital Ocean. Now you can expand upon this with a volume for your media!

Format the Volume

To format the volume I followed Digital Ocean’s instructions. These you will get once a volume has been setup. In a popup you will get the line needed for your volume in your region. Idid a

sudo mkfs.ext4 -F /dev/disk/by-id/scsi-0DO_Volume_volume-lon1-01

Add directory to store media

If you have this WordPress setup from scratch and just start a website you can skip this as the media directory is yours to use

If you do not already have the media directory where you store the media you can create one. Most likely you do. We however moved the old sites one inside the wp-content/uploads for our multisite media to a backup location and then recreated it using:

sudo mkdir -p sites

This as we would later sync all that data from the production server.

Mounting the Volume

Next we had to mount that directory so that it would load all the data from the volume instead of the actual Droplet. We did that using:

sudo mount -o discard,defaults /dev/disk/by-id/scsi-0DO_Volume_volume-lon1-01 /srv/www/staging.domain.com/shared/uploads/sites;

And to make the mount permanent do a:

echo /dev/disk/by-id/scsi-0DO_Volume_volume-lon1-01 /srv/www/staging.domain.com/shared/uploads/sites ext4 defaults,nofail,discard 0 0 | sudo tee -a /etc/fstab

Then we checked if the mounting was successful:

cat /proc/mounts |grep staging
/dev/sda /srv/www/staging.domain.com/shared/uploads/sites ext4 rw,relatime,discard,data=ordered 0 0

As you see it was. And this means for most of you that you are done. You will have a Digital Ocean Volume for WordPress Media. We however needed to get the media copied over still.

Rsync Data

If you have this setup from scratch and just start a website you can skip this

Normally if you have a media volume already and need one for staging or another clone of the server you can just clone the volume and set up a new one and attach it. We only had an issue as the production server and volume were in a different region than staging so we had to set up a volume from scratch at both locations and sync the data between them:

ssh -o ForwardAgent=yes web@xxx.xxx.xxx.xx "rsync -aze 'ssh -o StrictHostKeyChecking=no' --progress /srv/www/domain.com/current/web/app/uploads/sites/ web@xx.xxx.xx.xx:/srv/www/staging.domain.com/shared/uploads/sites/"

Digital Ocean Monitoring Beta Setup

Just installed Digital Ocean  monitoring beta on one of my Digital Ocean droplets where I have Trellis running for a WordPress client of mine. It is a new way to monitor bandwidth, memory usage and I/O. And also a way to get alerts when your droplet gets hit hard on one of those metrics.

Installation Digital Ocean Monitoring Beta

Setting it up on an existing droplet was quite straightforward. Did have to reboot once. Probably as I did an upgrade running a:

sudo unattended-upgrades -d

just before I got to setting up the monitoring with this easy curl command:

curl -sSL https://agent.digitalocean.com/install.sh | sh

NB Needs to be run as root or using sudo

That ran an ssh script downloading and installing the agent. And it started working pretty quickly afterwards. Just give it like 10-15 minutes.

Monitoring Alert

I also set up a monitoring alert warning me when CPU reached 70% as well as one when memory exceeded 40%.

Here is an example of an alert policy setup screen:

Alert Policy

 

And here is the list of alerts I set up for one of these droplets:

Digital Ocean Alerts

 

As you can see setting up an alert is really straight forward. And warnings can be emailed or sent to your Slack account. Really awesome. Though an app that sends push notifications would even be better. There is an API though. Will have to look into that some other time.

Graphs Beta

Graphs beta will start working as soon as you have set up your monitoring on your droplet. As you can see below it is still pretty empty. But that is as I just started using it. I like the layout. Easy to see things from a bird’s eye view so to speak.

Digital Ocean Graphs Beta

Graphs will be good to check out the history when you do get an alert. This to see if there was just a spike or whether the usage has gone and your droplet may need an upgrade.

Bonus

Moving on the graph of one of the monitors will show you details:

Memory Monitoring Details