Which interprets PHP faster on Ubuntu Server 12.04 32-bit, Apache or Nginx?

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?


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


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?


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.