Question
Should I use Nginx or Apache for my Wordpress Install?
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/)
- How To Install WordPress with LEMP on Ubuntu 18.04 - NGINX
- How To Install WordPress with LAMP on Ubuntu 18.04 - APACHE
- 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.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
Not sure on the
.htaccess
requirement for wordpress plugins, but take a read through @jtittle ’s amazing answer to the “nginx vs apache for wordpress” question here for more context: https://www.digitalocean.com/community/questions/should-i-choose-apache-or-nginx-for-large-wordpress-site-or-best-environment?answer=25336Hey @aha thanks for chiming in! I gleaned some insight from that question and the answer from @jtittle before posting, as I’ve been doing this research. I was hoping for some deeper discussion about this
When it comes to scaling any PHP application, this is a common question. Apache or Nginx or Apache with Nginx? I think this is as important a question as tabs vs. spaces.
Apache gets much hate for not being scalable or reliable. This hate comes from the old days of poor defaults and modphp. With modphp, apache spawns a PHP parser even when static files are requested, and that results in higher memory usage per child process. In other words, you end up using ~200 MB memory when processing WordPress files and another ~200 MB memory to serve each image that goes along with the site.
Throw this configuration in a high traffic situation, and like clockwork, it crashes when the memory runs out.
In reality, apache httpd powers popular sites like apple.com and adobe.com. If you use php-fpm with httpd, it scales very well for WordPress, and you get to keep your .htaccess rules.
Nginx uses php-fpm by default with the fastcgipass mechanism. This gives it an edge in the benchmarks when compared against apache with modphp.
If you compare Nginx and Apache side by side with both using php-fpm, the results are almost identical.
So which one is better?
Well, it comes down to the team that needs to support this site regularly. If the team is comfortable with httpd, go for it. If they are comfortable with nginx, use that instead.
Some people like to use nginx in front of httpd to serve static files and let apache handle php requests. While this provides the best of both worlds, I prefer keeping my stacks lean. Lean stacks make troubleshooting easier when things go wrong.
One argument I hear a lot against using only nginx is that you don’t get to use .htaccess, which may break WordPress plugins.
I manage ~15,000 wp sites, and for 99% of them, the following nginx config is enough to replace htaccess:
location / {
try_files $uri $uri/ /index.php?$args;
}
For anything else more complicated, offloading it to 3rd party services (WAFs, CDNs) scales better.
The bottom line is you can get identical performance with Apache or Nginx when using php-fpm. Go with the one you are comfortable with and look for optimizations on another layer. Unless there is a clear need for it, avoid apache+nginx and keep your stack lean.
P.S.: Apache httpd has come a long way from its mod_php days. You can even use Lua scripts with httpd just like Nginx and Resty!