I've been doing research (and testing) for several days on the pros and cons of using Nginx over Apache.

My main question is, is it worth while to use Nginx for a SaaS built on PHP and MySQL?

Just about all of our static files will be served from Amazon S3. That only leaves php and the database for the server to handle.

The server will be a quad core with 8GB of RAM with 10K disks in RAID 10.

I know at launch there won't be much of a difference since the overall traffic load will be fairly low. However, I'd rather plan for the future now, than have to reconfigure our app to work on a completely different web server.

I've tested the app on apache and nginx. Apache was easy to set up since it was pretty much a basic LAMP stack with a few extra packages. With nginx it has been much more work - and I still don't have it set up entirely (at least not something that I would want to push to production). I've been using Nginx .0.8.50, php5.3.3 with php-fpm and APC. Nginx has required compiling several libraries and the config files are not something I'm used to - and still need a great deal of work.

Is it really worth our time to worry about Nginx since most of our app is dynamic?

Thanks in advance!


I wouldn't worry about nginx or any of the other fancy new tools out there until you have a reason to. DO plan your application appropriately (try not to make a giant mess). Things like keeping your static content separate from dynamic, and setting proper apache cache headers will get you a lot farther than deploying tools like nginx and varnish.

Keep good traffic stats - and keep your code & content organized - when you get busy enough to actually need to move to one of these technologies to save real money... you'll be in a position to do so.

Simpler is better. You don't need nginx unless apache is causing you too much overhead. You probably don't need Varnish until your application is being hit with content that could be statically served elsewhere (which you could do other ways as well). That said - I'd be tempted to design for something like Varnish as part of the architecture of the application rather than worry about Apache... but hard to say.

Addendum: I admin some moderately big PHP websites that are extremely mission critical. Money flushes down the toilet when something goes wrong. Some attention to client-side and shared-cache caching, decent web design, and a little bit of shared-session via mysql gets you a long way - unless you have app-logic that's really slow and you really need to separate out static content from your application, you don't need all the new toys, as awesome and tempting as they are. Your bottleneck is most likely your DB in the first place- memcache may even be too much - cache_lite goes a long way too (paying attention to caching -vs- not paying attention is far more important than which caching technology you pick, until you get really big)


This is a bit of a me-too answer, but regardless:

Why bother? The usual argument for using a light-weight web server like nginx is to provide a ton of lightweight threads for serving static content, allowing you to serve more concurrent static content requests per MB of memory.

Since you're off-loading your static content, this isn't a concern.

If (nearly) every request that hits your server is going to be interpreting PHP, you might as well just stick with a well-tuned apache+mod_php+APC.


Well given that you're clearly several manhours in figure out how much your employer pays you an hour and ask yourself if you've saved that much worth of hardware (or ever will).

Getting caught up in the analysis-paralysis of $incumbent vs. $pop-alternative is by far one of the least productive things sysadmins do. Solve the problems you actually have (like the site not being up yet) and if you ever get to a point where you have so much traffic that cdn's, http caches, loadbalancers, and a couple hundred dollars worth of RAM aren't enough then worry about optimizing for that last 10%.

  • Well, that's the problem...I am the employer - and I'm not paying myself anything. All my money is going to developers, marketing, research and hardware. I do have a SA on staff but he's only part-time at the moment while he finishes school. He's really good at what he does but I don't want him to be the only one in our org that knows how this stuff works - hence the reason I'm asking for outside opinions while I try and learn a bit more. The general consensus seems to be use what you know and worry about complete optimization later, yes? – teamcrisis Sep 16 '10 at 22:46
  • Well in that case the ROI is divide by zero :) Seriously the lesson here is not apache vs. nginx, its "thing the vast majority of professionals make their living with" vs. "thing thats a hot topic". You can fill in the blanks: should your employees run linux on the dekstop instead of windows or would that be a waste of time? Should the DB be mysql or postgres? The trick is to not let yourself get sucked into this stuff and waste time on it. Geeks can make anything look like a coin-toss/angst-ridden decision when In reality if you look at marketshare its night and day. – cagenut Sep 16 '10 at 23:07

I probably wouldn't bother with something like this, unless I was sure I needed it. I've found that Apache works really well, and has been the best choice for me in all but a few very specific and specialized cases. If Apache was easy to setup, and you've got that configuration working and correct, decide whether you need further optimizations before you perform them.

Do some benchmarking and load testing. Can your current setup manage the anticipated load? If it can, then congratulations, you're already done with this step. If not, is CPU on this box actually your limiting factor (as opposed to RAM, or disk, or network bandwidth, or whatever). Along with the load testing, do some profiling. If you run some benchmarks and you see that PHP is using 98% of the CPU, and Apache is using 1% of the CPU, optimizing the CPU usage from the web server can never buy you more than 1% improvement.

  • Thanks for your reply. I've been leaning the same way as well. I honestly think our two biggest issues will be RAM and Disk read/ write. Would you suggest memcache/varnish before worrying about replacing apache? – teamcrisis Sep 16 '10 at 22:35
  • It's hard to say, and depends on where the bottleneck is. memcache will act as something of a DB cache in front of MySQL, while varnish will do the same thing for a web server. So much is dependent on your specific workload, and it's impossible to accurately guess where the hot spots might be without knowing a lot more about it, and doing some benchmarking. – Christopher Cashell Sep 20 '10 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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