I have currently installed Apache on my 12.04 32-bit Ubuntu server, but I'm interested into switching to Nginx. I have read a number of comparisons and reviews, where Nginx is faster than Apache serving static content, but these don't cover PHP performance.

Here is my question: How does Nginx compare to Apache regarding performance of PHP processing? Is Nginx also faster for PHP?

  • 2
    I think this should probably be closed. I've tried editing it to more narrowly define a question, so please take a look and revert my edit if you disagree. The original was way too broad. – Tom Brossman Jul 23 '13 at 16:28
  • 1
    This is too broad and opinion-based for this site. – Thomas Ward Jul 23 '13 at 16:45
  • 1
    @ThomasW. The question isn't to broad, instead it is very simple and could be rephrased to: "If I replace Apache with Nginx will PHP processing be faster on my server?" This should be answered simple with some explanation: Nginx with PHP-FPM is faster than Apache with mod_php, but the resulting improvement depends on the environment (PHP code, users, hardware, etc.). One can of course over-elaborate on every question, but one can also exercise in the art of giving short answers. E.g.: simple.wikipedia.org/wiki/Data_%28Star_Trek%29 vs en.wikipedia.org/wiki/Data_%28Star_Trek%29 – LiveWireBT Jul 25 '13 at 23:41
  • 1
    @LiveWireBT Want to edit this and vote to re-open then? I think there is an interesting, on-topic question in here somewhere. I don't know enough about it to improve the question further though. – Tom Brossman Jul 27 '13 at 17:30
  • 1
    I think this could still be made more specific by mentioning various different PHP tasks that the OP may be interested in, as performance of an interpreter often depends to some degree on what sort of code is being run. (Only the author of the question could likely add that information.) Also, information about the non-PHP performance benchmarks mentioned may help too. With that said, even now I think this may be considered narrowly tailored enough for our site. – Eliah Kagan Sep 9 '13 at 17:18

Here is a comparison between Apache and Nginx listing some advantages and disadvantages.

Apache, by contrast, approaches large numbers of requests by spinning off more processes to handle them, typically consuming a lot of RAM as it does so. And sometimes Apache gets a little anxious about the size of its repast. Apache is available from the Ubuntu package repositories with a quick sudo apt-get install apache2.

  • Apache, is the most established web server today and powers more sites on the web than any other server.
  • Apache is an established, flexible web server that many enterprise-level customers rely on for delivering both dynamic and static content.
  • Apache can run on a range of operating systems, is well-maintained, and its ubiquity means that a substantial amount of user-generated documentation exists.
  • Apache consumes more memory under high server loads, which can result in degraded performance.
  • Due to how robust it is, Apache also comes size, which leads to more memory consumption.

Nginx (pronounced "engine-ex") is a lightweight Web server with a reputation for speed, speed, speed. It differs from Apache in a fundamental way—Apache is a process- and thread-driven application, but Nginx is event-driven. The practical effect of this design difference is that a small number of Nginx "worker" processes can plow through enormous stacks of requests without waiting on each other and without synchronizing; they just "close their eyes" and eat the proverbial elephant as fast as they can, one bite at a time.

  • Nginx is designed to be simple and lightweight, and to require fewer hardware resources than other web servers. It does this in part by using an event-based processing model, which generally requires less memory than a process-based server uses.
  • Nginx is fast at serving static web pages.
  • Nginx is newer, there is less documentation and support for it compared to more established web servers.
  • The lightweight design also means that it can be more difficult to customize, which might be necessary for large or complex configurations.

The difference is summed up succinctly in a quote by Chris Lea on the Why Use Nginx? page: "Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache."

When you compare Nginx vs. Apache, both are open source software, and both camps have a community of vocal advocates. Nginx is available from the Ubuntu package repositories with a quick sudo apt-get install Nginx.

In the end, both Nginx and Apache web servers are solid solutions although each has their fortes in given situations. Nginx’s main strengths include serving up static web pages quickly, and light consumption of memory and hardware resources. Apache is the established and versatile workhorse, with abundant module availability and documentation. Depending on your business needs and technical requirements, one or the other, or even a combination of the two, may be right for you.

Hope that this helps.

Source:Lee Hutchinson & Lukasz Kujawa

  • 1
    Note that Apache is also available from the Ubuntu package repositories with a quick sudo apt-get install apache2It's not a difference between the two ;) – GabLeRoux Jul 23 '13 at 15:51

Nginx with PHP-FPM is generally faster than Apache with mod_php, but the resulting performance improvement depends on the environment (PHP code complexity, users/load, hardware, etc.), where you deploy your solution or web application.

We need to dig a bit deeper into webservers to understand why there are no plain comparisons of PHP performance for webservers.

PHP support in Nginx

Apache uses mod_php to interpret PHP code. Lighttpd, a competitor to Nginx during the early days, used its own spawn_fcgi (another FastCGI implementation) to improve speed and resulted in being able to serve more users with the same or less amount of resources as Apache. Thus gaining popularity.

Nginx is a bit more different to Lighttpd. As of today Nginx supports a lot of functionality and can also be configured to run spawn_fcgi, but it was never as closely bundled with it as was Lighttpd. Which allowed to re-think about PHP support for webservers and probably led to the FastCGI Process Manager project (PHP-FPM).

PHP-FPM is available in Ubuntu via the php-fpm package as of 12.04. The Ubuntu package comes pre-configured, but it's worth reading up on how to fine tune pool parameters for your needs (impatcs: complexity of code, available RAM and CPU processing power, execution time). There are also guides available which explain how to setup dedicated pools for different applications yielding for not only more performance, but also security. If you care about performance you should take the time to get to know the main components of your new server stack.

Configuring Nginx

Please read the Nginx documentation in the english project wiki. I found it to be very helpful for understanding how Apache is configured, why Nginx does things differently (e.g. if is evil) and how you achieve speed improvements with Nginx.

If you replace Apache with Nginx and try to configure it the same way as Apache, you won't get much speed improvement at all or your configuration will just not work.

Nginx basically aims for reducing complexity while still providing a wide feature set.

And who said you cannot run an Apache behind Nginx?

  • "Nginx with PHP-FPM is generally faster than Apache with mod_php" Can you give a source on that? – Dave Lancea May 13 '14 at 20:09

Usually it is said, that nginx is faster, when there are lots of static content, and the number of user requests is high. If you have a small website, it is really up to your preference to select your web server. But to answer the question itself, the difference in PHP processing itself should be negligible.


You can use nginx , it is very fast vs Apache2 with bot static and dynamic and response time also quick then other.

It also work fine with php , rails and other scripting language.

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.