WordPress Performance Profiling with Sail CLI

Having to deal with performance problems on a WordPress site is never too pleasant, partly because the tooling is not great. Things like Query Monitor and the Debug Bar series of plugins can certainly help to some extent, but often times they’re not enough, because they do things in PHP, which is limited to, well… PHP.

Moreover, when reporting on database queries or remote HTTP requests, these tools will rely on the WordPress database and HTTP APIs, so if some theme or plugin happens to do a direct call to mysqli_query(), or file_get_contents(), etc., which is often the case with external third-party libraries, then you’re out of luck.

This is why you often need an actual profiler to get the job done.

Continue reading

Configuring Mailgun for WordPress with Sail CLI

Mailgun is a robust e-mail delivery service with both API and SMTP support, and a generous trial of up to 5000 e-mails/mo for three months. Together with Mailgun, we’ve developed a couple of default blueprints for Sail to ease the configuration.

  • mailgun-dns.yaml: this blueprint adds all necessary DNS records for mail delivery through Mailgun, as well as domain verification at Mailgun
  • mailgun.yaml: extends the default Postifx configuration with Mailgun-specific settings

If haven’t used sail before, it’s a free and open source CLI tool, that helps you provision and deploy WordPress applications to the DigitalOcean cloud. Sail is available for Windows, macOS and Linux. Click here to learn more about Sail.

Add and Verify a Domain

Before running any Sail blueprints you’ll need to get an account at Mailgun. Then add your domain name to Mailgun under SendingDomainsAdd New Domain. After the domain is added you’ll see a list of DNS records, required for mail delivery and domain verification (SPF, DKIM, MX and CNAME records).

Next, add this domain to your DigitalOcean account using Sail:

$ sail domain add example.org

Make sure the domain name server records at your domain registrar are pointed to the DigitalOcean DNS servers:

  • ns1.digitalocean.com
  • ns2.digitalocean.com
  • ns3.digitalocean.com

Here’s how to do that with common domain registrars.

To add the Mailgun DNS records to your domain, run the mailgun-dns.yaml blueprint with Sail:

$ sail blueprint mailgun-dns.yaml
> Domain Name: example.org
> DKIM Record Name: mx._domainkey
> DKIM Record Value: k=rsa; p=...
# Applying blueprint: mailgun-dns.yaml

Note: the DKIM record name should not include the full host/domain, but only the DNS record name. So if the full host name is mx._domainkey.example.org, you’ll need to enter just the mx._domainkey part (no trailing dot).

After the DNS records have been added to your DigitalOcean account, visit your Mailgun control panel and under SendingDomainsYour Domain, hit the Verify DNS Settings button.

Configure Postfix for Mailgun

After verifying the domain with Mailgun, grab your SMTP settings from your Mailgun control panel under SendingDomain SettingsSMTP Credentials. You’ll need the SMTP login and password here. You might have to reset the password if you’d like to use the default postmaster user.

Armed with these credentials, you can now run the mailgun.yaml blueprint with Sail:

$ sail blueprint mailgun.yaml
> Mailgun SMTP Login: postmaster@example.org
> Mailgun SMTP Password: ...
> From name: WordPress
> From e-mail: hi@example.org
# Applying blueprint: mailgun.yaml

The From name and From e-mail values are what’s going to be used with wp_mail() by default in WordPress, when setting the From: header for e-mail delivery. For best results, it is recommended that you use an e-mail address within the domain you’re using with Mailgun.

This blueprint will also create a mu-plugin on your production site, which sets the from name and e-mail. Be careful not to overwrite/delete this plugin when deploying changes to your production site. It is always recommended to run a `sail download` after any blueprint, to make sure your local copy is completely in sync.

Send a Test E-mail

You can send a test e-mail using Sail, to make sure it reaches your inbox:

$ sail wp shell
wp> wp_mail( 'your@email.address', 'Test from Sail', 'The body' );
=> bool(true)

If it has not reached your inbox, there are a few places you could look at for more information:

  1. Postfix logs using sail logs --postfix
  2. Mail logs in the Mailgun dashboard
  3. Your spam folder, of course

If you’re having problems with e-mail delivery in Sail for WordPress, please double-check to make sure your DNS records are correct, your SMTP credentials are okay. If they are and you’re still experiencing trouble, feel free to reach out Sail support or Mailgun support for help.

Mail Performance

I’ll be doing a mail performance test of this configuration, and possibly fine-tuning it during a live stream via Koddr.io on September 28th at 17:00 UTC. Let’s see what it takes to send 10,000 e-mails from a five-dollar DigitalOcean droplet.

If you’d like to be notified (and also support us in general), you can:

See you soon!

Fun with Blueprints in Sail CLI for WordPress

Blueprints allow Sail users to define an environment, where their WordPress applications will be provisioned.

Currently blueprints support plugins (wp.org or custom), themes, options and wp-config.php constants. In future updates we’ll add support for Redis/Memcached setups, Mail, security (fail2ban, etc.) and much more. Possibly some DigitalOcean features too, like floating IPs and volumes.

Here’s a demo overview of how blueprints work:

More information in the GitHub repo.

Sail: Deploy WordPress to DigitalOcean

Sail is a free and open source CLI tool to provision and deploy WordPress applications to the DigitalOcean cloud. Here’s a quick video demo of how it works:

I’m a DIY guy when it comes to WordPress hosting, so I like to get my hands dirty with servers, code, configuration and everything else. I’ve been using virtual servers at DigitalOcean for small WordPress projects for a very long time, and it’s great, and also very affordable.

However, it’s a bit annoying to do routine maintenance on existing servers, or provision and configure new servers for newer projects so, like most developers, I wrote a bunch of scripts, and used them for many many years.

Over the last couple months I’ve decided to clean up (rewrite) all those scripts and package them into one easy to use CLI tool, which I called sail. It’s open source on GitHub, and available for Linux, MacOS and Windows through Homebrew and PyPI.

The Competition

Sure, there are plenty of existing products and services for managing WordPress on DigitalOcean and other cloud providers, and trust me, I tried them all. Every single one of them beasts. Here are some of the problems I had:

  • A lot of them don’t provide vanilla WordPress, they bundle stuff from their partners which I don’t want
  • Most of them lack any sort of deployment tools, so I have to set things up on my own
  • Many of them won’t give me root access to the server I’m paying for, and some will not even let me use my own DigitalOcean account to run the VMs
  • Most of them are web GUIs, while I always prefer the command line for such things
  • Some of them charge me double the droplet price for features and services which I’ll never use

Sail is free and open source, and it allows you to:

  • Quickly provision a clean WordPress site to your DigitalOcean account
  • Deploy code changes and rollback in quick atomic operations
  • Add domains and free SSL certificates through Let’s Encrypt
  • Create and restore complete file and database backups
  • Quickly access server logs, production SSH, WP-CLI and MySQL shells
  • With full root access, and all from the command line


While my focus right now is to complete and polish all the core Sail features, I do have some more exciting things on the roadmap for the next few releases. This is not a promise, but rather a taste of what’s coming next:

  • Blueprints, which will allow you to specify additional plugins, themes, settings and server software to launch with your Sail project
  • Staging, and all the pushing/syncing to and from and between
  • Profiling, because every millisecond counts


The easiest way to get Sail is from Homebrew or PyPI. It run on Linux, MacOS and Windows (via WSL). Give it a spin, I think you’ll love it. And if you don’t, let me know why in the comments below.