Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Jan 5 '10 at 3:12

This question came from our site for professional and enthusiast programmers.

4 Answers 4

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.

share|improve this answer

The author of nginx says that nginx is aimed on serving static files and being frontend, forwarding request which require dynamic pages to other servers like apache.

Another good idea is to cache apache's dynamic request with nginx if data is rarely updated, for example, an archived blog post.

share|improve this answer

In most cases nginx. For highload projects nginx + php + php-fpm is excellent choice.

share|improve this answer

I may be mistaken, but I think nginx only serves static files (it doesn't support PHP). I inferred this by reading here: http://nginx.org/en/.

share|improve this answer
9  
nginx supports PHP via fastCGI tomasz.sterna.tv/2009/04/php-fastcgi-with-nginx-on-ubuntu –  Frank Farmer Jan 5 '10 at 3:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.