Adventures of a Technomancer

Adventures in WordPress Vol. 6 - Summary

Here we are, after a few changes to the hardware, software and network it's time to see if all the hard work has paid off.

In summary the things I changed where;

  • Decreased apache mpm servers
  • Installed fail2ban
  • Removed 13 plugins
  • Optimised images using jpegoptim
  • Converted stock WP to Bedrock for better manageability
  • Changed MySQL to MariaDB
  • Updated PHP from 5 to 7
  • Reconfigured a WP cache
  • Added an extra CPU and 1GB of RAM for a total of 2 CPUs and 2GB of RAM
  • Installed Memcached
  • Enabled a CDN

These are the results...


Unfortunately I didn't grab one before I started, so I disabled most of the modifications and CDN to get a rough picture.


Take a look at that load time! Wowza.

From 9.2s to 1.0s, that's a crazy 89.1% reduction in load time!

I managed to keep the mobile user experience at a reasonable 100/100 too.

The only thing that's bringing down the score is the unscaled images.

Adventures in WordPress Vol. 5 - CDN

One of the last things to tackle for the moment is setting up and managing a CDN or Content Delivery Network.

Before picking a CDN provider I needed to get an estimate on how much traffic the site was using. Luckily there's a console based network traffic monitor for Linux called vnStat.

To enable vnStat just requires one command;

vnstat -u -i eth0  

Checking the estimate using vnstat -d showed that we'd be sending about 300GB this month, yikes.

                rx      |     tx      |    total    
estimated    345.95 MiB |    9.04 GiB |    9.37 GiB

But thankfully after a few days of gathering data the estimate became a more reasonable 120GB per month.

➜  ~ vnstat --months

 eth0  /  monthly

       month        rx      |     tx      |    total    |   avg. rate
      Jun 16       3.50 GiB |  119.66 GiB |  123.17 GiB |  398.61 kbit/s  
      Jul 16       6.51 GiB |  147.34 GiB |  153.85 GiB |  481.84 kbit/s
      Aug 16       3.94 GiB |   62.99 GiB |   66.93 GiB |  209.62 kbit/s  <- CDN enabled here
      Sep 16      20.39 GiB |   31.93 GiB |   52.32 GiB |  182.52 kbit/s

After doing some searching and consulting with Nicole, we decided to give MaxCDN a try. Their 9$ for 100GB looked to be a reasonable price for the amount of traffic the server was receiving.

The entire process from signing up to enabling the CDN was super easy and only required 2 settings to be configured.

The only step that wasn't required was adding a CNAME DNS entry for cdn.bittenbythetravelbug instead of [long hash], this keeps things tidy and well presented to end users who snoop around the sites source code.

Adventures in WordPress Vol. 4 - Hardware and Software

With the foundation (or 'Bedrock') of this upgrade complete it's time to see what some upgrades will do.

The plan of attack is to change MySQL to MariaDB, upgrade PHP from 5.6 to 7.0 and upgrade the DO Droplet to something with more power.

MySQL -> MariaDB

Why MariaDB?

For a few reasons, mostly for the features and to support OSS. There are some speed enhancements if the benchmarks are to be believed.

Like before, I'm backing up all databases before I change anything. Just in case.

$ mysqldump --all-databases -u root -p | bzip2 -c > /root/backups/all-$(date +%Y-%m-%d-%H.%M.%S).sql.bz2
$ apt-get remove --purge mysql-server mysql-client mysql-common
$ apt-get autoremove
$ apt-get autoclean
$ apt-get install mariadb-server

PHP 5.x -> PHP 7

$ add-apt-repository ppa:ondrej/php
$ apt-get update
$ apt-get install php7.0 php7.0-mysql php7.0-mbstring php7.0-curl php7.0-gd php7.0-intl php7.0-xml php7.0-zip php7.0-fpm
$ php -v
$ a2dismod php5
$ a2enmod proxy_fcgi setenvif
$ a2enconf php7.0-fpm
$ service apache2 restart

Why PHP7?

This one's easy.

Twice the speed. Zoom zoom baby!

Resizing the droplet

Originally Bitten by the Travel bug was hosted on a simple 512MB RAM Digital Ocean droplet and was able to deal with the 40k hits per month.

Once the site started getting even popular (upwards of 100k hits per month) that original 512MB of RAM was not enough, so we picked the 2GB droplet and decided to monitor resource usage over 3 - 4 months and see if the smaller droplets would suffice.

Thanks to DO's Flexible Resize feature this can be done with minimal downtime.

Adventures in WordPress Vol. 3 - Converting WordPress to Bedrock

Bedrock is a modern WordPress stack that gets you started with the best development tools, practices, and project structure.

This post will be a little light on descriptions as it's fairly straightforward to move an existing WordPress project into a Bedrock stack. It's mostly moving directories around.

Backup the existing database

Always a good idea before messing with the database and performing a lot of updates.

$ mysqldump [database] -u [user] -p | bzip2 -c > [database]-$(date +%Y-%m-%d-%H.%M.%S).sql.bz2

Update the database

Replace all instances of wp-content with app

> UPDATE `wp_posts` set `guid` = replace(`guid`,'wp-content/uploads/','app/uploads/');

And again for post_content:

> UPDATE `wp_posts` set `post_content` = replace(`post_content`,'wp-content/uploads/','app/uploads/');

Moving plugins to composer.json

    "wpackagist-plugin/wp-instagram-widget": "^1.9",
    "wpackagist-plugin/akismet": "^3.1",
    "wpackagist-plugin/amazon-link-engine": "^1.2",
    "wpackagist-plugin/google-analytics-for-wordpress": "^5.5",
    "wpackagist-plugin/jetpack": "^4.0",
    "wpackagist-plugin/w3-total-cache": "",
    "wpackagist-plugin/wordpress-seo": "^3.3",



$ cp -r ./wp-content/themes/[theme name] [bedrock]/web/wp/wp-content/themes

And just like that we're now running a Bedrock based wordpress installation.

CDPATH with zsh

Here's some awesome knowledge passed along from @bradleyfalzon.

If you add CDPATH to ~/.zshrc you can tab complete into those directories without typing the full path.

Very handy if you happen to run several vagrant instances or a verbose directory structure to mimic production.

typeset -U path cdpath fpath

setopt auto_cd  
cdpath=($HOME/scripts /mnt)

zstyle ':completion:*' group-name ''  
zstyle ':completion:*:descriptions' format %d  
zstyle ':completion:*:descriptions' format %B%d%b  
zstyle ':completion:*:complete:(cd|pushd):*' tag-order \  
        'local-directories named-directories'

When tab completing a cd you'll end up with something like this;

The same can be done is bash by adding the following to your ~/.bashrc.

export CDPATH=.:$HOME/scripts:/mnt