Setting up WordPress with the Nginx Web Server instead of Apache

- August 12, 2016

WordPress If you’re reading this, then it’s more than likely you want to use the self-hosted WordPress software and not use the commercial WordPress service.

The self-hosted software gives you more control and offers a lot more flexibility. It also lets you run the advertising services you want to use. Running the commercial offering won’t cost you a thing unless you want more than the basics. Self-hosting isn’t terribly expensive until your website gets extremely popular. Done correctly, it won’t ever get expensive.

Installing and Configuring WordPress

To run WordPress, you need a web server, PHP-FPM and MySQL (or MariaDB, preferably). Both Apache and Nginx are well-supported web servers and I’m sure it’ll run with others (most people start with Apache). I already wrote about setting up the required daemons on an Ubuntu server. The self-hosted software website can take you through installing WordPress as well as its first configuration, step-by-step if necessary.

To get WordPress working well with Nginx, the page for it at provides a lot of details on how to configure it properly. If you want it work better, you should read this article published by an writer.

By default, the pages and posts are served dynamically through PHP. This works fine until you get more than a few posts published. The database is the biggest bottleneck even though a single-page object cache exists. If you leave it set up this way, you’ll find your memory usage going through the roof and your speed decreasing.

To get better and faster performance, you need a persistent object cache (like APCu, Memcached, XCache or Redis) and a full-page cache (like WP Super Cache, W3 Total Cache, Hyper Cache or Comet Cache). Some of the full-page caching plugins configure a persistent object cache, but not many.

The best full-page caching plugins don’t access PHP at all on the cached, static pages. That means the database isn’t accessed either. Page speed is important and the time to first byte is important.

I wrote my custom caching script to bypass WordPress completely for visitors. The back-end administration functions as normal. The caching script is activated by a real cron job. It runs every minute but exits immediately if there aren’t any cached pages to create or update.

What about a Mail Server?

Years ago, a mail server was a necessity. Today, it’s only necessary for branding purposes, with your domain name as part of the e-mail addresses being used. Even so, you don’t actually have to install a mail server because Google and other entities will do e-mail hosting for you.

If you install a mail server, it’s actually a two-part system. One daemon is for receiving and one is for sending. With WordPress, you only need to send and you can do that with msmtp, an SMTP client. To install it:

apt install msmtp msmtp-mta

Edit the configuration file:

nano /etc/msmtprc

You can read the documentation, but use these lines for gmail:

tls on
tls_starttls on
tls_trust_file /path-to/ca-certificates.crt
account default
port 587
auth on
password yourpassword
logfile /var/log/msmtp.log

The tls_trust_file for Debian, Ubuntu and other Debian derivatives is “/etc/ssl/certs/ca-certificates.crt”. Once you verify everything’s working, you can put a “#” in front of the log file line.

As far as mail server ports go, the only one I have open is 587 (TCP out). I’ve been receiving my website mail for years doing it this way.


Categories: Technology

Previous and Next Articles (if any):

« »


Your comment will appear below the form when it's approved. When the page redisplays after hitting the send button (it takes a few seconds), your comment has been sent.

When replying to someone else's comment, please start the comment with "@" and the name so I can put it in the right place.


Please read some of my more important pages if you have the time:

Comments Policy           Privacy Policy

RTCXpression established Feb 28, 2011
Copyright © 2013-2017 RT Cunningham
Hosted at Digital Ocean