Should I use Nginx or Apache for my Wordpress Install?

September 11, 2018 958 views
LEMP LAMP Stack Nginx WordPress

tl;dr - Nginx or Apache for WP install, and WHY?

Which of these web server options are the best option for installing and sustaining a Wordpress instance? After reading dozens of articles and forum posts I'm leaning towards Nginx, but there may be some drawbacks as mentioned by @jsamuel, in [this discussion response](https://www.digitalocean.com/community/questions/why-is-apache-used-over-nginx-for-wordpress-one-click?

"It is possible to host WordPress using only Nginx without Apache at all, but because WordPress won't be able to use .htaccess files (.htaccess files are an Apache feature, they don't exist in Nginx), you'll need to regularly be reconfiguring Nginx for various WordPress plugins. You should only take that approach if you're comfortable with the command line and server administration."answer=31242/)

  1. How To Install WordPress with LEMP on Ubuntu 18.04 - NGINX
  2. How To Install WordPress with LAMP on Ubuntu 18.04 - APACHE
  3. How To Use the WordPress One-Click Install on DigitalOcean - uses Apache

Is the ability to use .htaccess files still a concern if one was to use Nginx? Any clarification on this would be so helpful.

2 comments
1 Answer

Hey friend!

In terms of performance and sustaining high traffic, Nginx wins every time. It's been that way for a while now, not quite one of those things that goes back and forth every month or so. Whether it's a base install or both are tweaked for max performance, in any situation where it's a 1:1 comparison, Nginx pulls ahead.

As for the .htaccess thing, I'm not sure I share the linked perspective. You need your basic rewrites and perhaps some additional ones to accommodate a good caching plugin. You should be able to find those in template form with light Google searching. Beyond that, I really have never met a plugin that wrote new items to .htaccess that I also recommended to people. There are a lot of very popular Wordpress plugins that I don't like, and I think you can get along fine without. Security plugins being one of them. I'll take http auth on wp-login any day, lightweight solution and additional security had by all.

Moving back to web server choices. There is, of course, more to life than benchmarks. When a visitor hits your page and it loads in an acceptable amount of time to not cause them to want to leave, performance is fine. As long as you're not running Apache with Prefork MPM, most people see no issue based on the web server itself. I use Apache and Caddy, I never use Nginx. I know it's the best, and I don't use it. I just don't like the configuration syntax. I don't need it, it isn't my preference, so I don't use it. Caddy sytnax speaks to me:

domain.tld {
        root /var/www/html
        log /var/log/caddy/domain.log
        errors /var/log/caddy/domain_errors.log
        gzip
        fastcgi / /run/php/php7.2-fpm.sock php {
                ext .php
                split .php
                index index.php
        }
}

So never forget that you have choices. Use what you want unless you need something else. Make it as enjoyable for you as it can be, you're the one that has to wake up at 3AM and fix it so it might as well represent your style.

Jarland

  • 👊 Awesome reply @jarland! Thank you so much for the explicit response. That's exactly the type of facts I wanted to be sure that I was considering.

    I've read similar things about Nginx. But I couldn't help but wonder why the "One-click Wordpress Installation" provided by Digital Ocean uses Apache instead or Nginx.

    With the relatively low amount of traffic I anticipate, I think either would be fine, but I'm so glad to have these additional things to consider ツ One thing is certain... I'm so glad I left Godaddy hosting and have come to the DO community!

    • Hi!

      I maintain the DigitalOcean one-click images and did some testing with a LEMP stack for the WordPress image a couple years ago.

      Originally the WordPress one-click was built using a LAMP stack because LAMP was at the time much more widely used and supported by the wider open source community. Most of WordPress' documentation also assumes you are using Apache and some tweaking is required for WordPress rewrites on Nginx that is not required on Apache.

      When I performed my review we did so to see if switching to LEMP would reduce base memory use on 512MB droplets (not a plan we offer any longer). MySQL can be a memory hog so that was our primary concern. My testing of the two alternatives found little difference in the base memory use.

      The choice to stick with LAMP was made both for those technical reasons but also to ensure that a user spinning up a droplet with the stack would be less likely to encounter confusing information if they run into problems or want to customize their installation.

      Our one-clicks are generally intended to be a quick-start to get going with a particular software stack but they are also often the first experience someone may have with the software. Taking that in mind we try to ensure that the one-click experience encourages that learning and provides something that as much of the community documentation outside DO as well as in our library will be applicable for.

Have another answer? Share your knowledge.