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 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.

share|improve this question
    
Once you've got the low-hanging fruit of speed improvements with APC, profile the site - first with Yslow, and then the PHP. It might be a mess, but a good developer could still find places where it could be enormously improved for just a little bit of work. –  Alister Bulman May 3 '09 at 19:27
    
Top tip from Topbit - bottlenecks can include poorly structured queries, lack of caching and using foreach with large arrays (referencing the "value" variable will prevent the function creating a copy of the array and lowers execution time) –  Andy Jun 6 '09 at 18:11
    
serverfault.com/questions/533905/… –  BigSack Aug 26 '13 at 18:13

3 Answers 3

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.

share|improve this answer
    
Why server images from another server/domain? –  cletus May 7 '09 at 3:10
    
To avoid cookies being sent with the request. If you're only interested in static content, why send any more that just the required headers in the HTTP handshake? There's enough overhead there without adding maybe a few hundred more bytes (heck, even the extra bytes for a minimal 'Cookie: PHPSESS=[MD5]\n' can add up if you're doing that for every request) –  Alister Bulman May 7 '09 at 23:02

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.

share|improve this answer
    
memcache would be great, the queries are awful. maybe I'll try to get a php guy on it. –  kch May 3 '09 at 17:12
    
Agreed, the queries aren't great but its certainly worth while putting up with them as it provides a great performance improvement over standard disk caching. –  Adam Gibbins May 3 '09 at 18:10

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).

share|improve this answer
    
Well let's be honest. Wordpress is a crappy (to say the least) blog system. It's actually one of the worst I've ever seen, down there with Drupal and a few others. Benchmarking a "hello world" script in PHP says that Apache does about the same as nginx (in fact a bit better), if your AllowOverride is set to None. –  Eduard Luca Apr 20 '13 at 0:57

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.