Nginx – Which is faster at serving up PHP pages, Apache or NGINX

apache-2.2htmlnginxperformanceweb

I've read quite a bit on the major benefits to running NGINX over Apache for serving static files. However, I have never seen an article talking about Apache vs NGINX for serving PHP pages.

Question: which is faster at serving up PHP pages, Apache or NGINX?

Best Answer

Personally, I think nginx provides the right split between the things it does itself (receiving and processing HTTP requests) and what it delegates to other processes (dynamic page generation). Whilst it is less effort to setup Apache to serve PHP requests, running everything within Apache is a bit of a security and configuration problem (all files that are accessed by all scripts run by all users on the server must be readable/writable by the user that Apache runs as, meaning that one user's PHP scripts can look at the data of other users); running each PHP site as it's own user in it's own FastCGI context is a much better option (at the cost of slightly more up-front configuration until you've got your site creation automation dialled in to do the right thing).

As far as "faster" goes, Apache with mod_php will probably be faster on a single request, as long as the machine isn't resource constrained (passing to an external FCGI listener and then back isn't quite as quick). However, Apache is much fatter (especially when running with mod_php), so you'll be able to serve more traffic with nginx before needing to upgrade to a bigger box.