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

Apache2nginxPHP

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?

Best Answer

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

Related Question