I need to serve a PHP app that handles lots of requests. I want to know if there's any real benefit in going with anything other than Apache, and what are the pros and cons of the alternatives.
I have some experience using lighttpd and nginx for Rails applications. Are they good contenders for PHP too? Any important setup tricks?
How about PHP accelerators, can they be used with these alternative servers, is it a good idea?
I'm on an OpenSolaris box.
Not sure if relevant, but, later on, I'm planning to put a Varnish proxy/cache in front of this server.
Edit:
I'd like to add that I have absolutely no intention of touching the app. It's the quintessential mess that PHP is famous for, and there's basically no time.
Apache is a good base with mod-php - and adding APC for byte-code caching, and some variable caching will help immensely, in fact, it's the most obvious thing you can do to speed up PHP scripts run-times (also, use Yslow to speed the HTML front-end and make sure that the database is optimised).
There are a few suggestions I'd add though, such as avoiding serving the images and other static content from Apache. I've got a separate (sub-)domain with a dedicated image server (I use thttpd, but nginx is also entirely suitable). Serving the images from an entirely separate domain name (or a CDN) would be ever better though.
NginX also has the advantage of being able to act as a proxy, which has it dealing with inbound connections, and then spoon-feeding the results back out - which means that the back-end producer processes of Apache2/Mod_php can work at full local-network speeds, rather than having to wait for the web-browser clients to catch up.
Varnish can perform additional work beyond what Nginx can do, but I don't know it so well - it might be you could just one one, or the other, but it's unlikely to have to use both.
nginx combined with php-fpm and xcache will provide massive speed improvements over any Apache solution.
Depending on your application incorporating something such as memcache may also provide massive caching advantages.
My Apache server with mod_php was running out of memory because of a Wordpress site. So after optimizing Wordpress, I moved on to Apache. I found that mod_fastcgi worked better than mod_fcgi. Moving PHP out of Apache reduced the Web server's footprint (from 38M to 4M per process). I also installed eAccelerators and have found that PHP runs faster. Also, if you pages have lots of includes (CSS & javascript), one of the tricks that I did with Wordpress was to compress the includes to one file which minimum whitespace (but this may be more of an artifact of Wordpress).
So I would suggest seeing of moving PHP out Apache (and into a separate process with mod_fastcgi [php-cgi]) helps. Please note that the PHP accelerators will increase the PHP process's memory requirements (which is another reason to move it out of the Apache process).