What is the difference between LAMP stack and LEMP stack?

On 24 July 2014, we launched a new OS template: Ubuntu 14.04 LTS (64-bit) with LEMP stack pre-installed. You might be wondering, what is a LEMP stack and what’s the difference from the existing and the more popular LAMP stack. Let’s talk about LAMP stack first. 🙂

LAMP Stack, with Apache

LAMP-logo

Picture courtesy of WebHosting Review Boards.

LAMP is an acronym for a model of web service solution stacks, comprising of these components: Linux (can be Ubuntu, CentOS, etc), Apache web (HTTP) server, MySQL database and PHP programming language. This is a combination of components which is very popular and has been around for quite some time.

The role for LAMP’s web server has been traditionally supplied by Apache, which has been (and is still) the most popular web server application on the public Internet. In fact, according to Wikipedia, Apache is noted for playing a key role in the initial growth of the World Wide Web. The application was originally based on the NCSA HTTPd server, and since the work on the NCSA code was stalled in early 1995, the development of Apache was started and quickly overtook NCSA httpd as the dominant web server, and has remained the most popular HTTP server in use since April 1996 until now.

Netcraft is an Internet security and data mining company which also has been conducting research on web servers and and publish the research reports on their website on a regular basis. Below is their report on market share of web server applications based on active sites, as of Aprl 2014:

 

netcraft-web-server-market-share

Source: Netcraft – http://news.netcraft.com/archives/2014/04/02/april-2014-web-server-survey.html

Based on the above graph, we can see that Apache is still the most popular web server applications being used by active sites all over the Internet with around 52% market share, followed by nginx with 14% and Microsoft IIS with 11%.

LEMP Stack, with nginx

lemp-stack

Picture courtesy of James Baltar.

What is a LEMP stack? It’s pretty much similar stack of components as LAMP, except the Apache is being replaced by nginx. Pronounced “engine-x”, which explain the E on “LEMP”, nginx is a HTTP proxy application with reputably much smaller footprints compared to Apache, allowing it to handle higher load of HTTP requests. According to Wikipedia, nginx uses an asynchronous event-driven approach to handling requests, compared to Apache’s default threaded or process-oriented approach, and its modular event-driven architecture can provide more predictable performance under high loads.

Based on Netcraft report above, we can see that nginx has been gaining traction since many people have started to use it in the year 2008, and have grown to become the second most popular web server application with 14% of market share in terms of active sites.

So, Nginx vs Apache, which one is better?

The answer is not that simple. I stumbled upon this great article from Anturis when I tried to search around on which one is better, Apache or nginx. Let me try to summarise in points on the advantage and disadvantage of using Apache and nginx.

Apache:

  • Has been available for so many years (since 1995), a lot of users and modules (mostly open-source) written to expand its functionality;
  • Process/thread-oriented approach — slows down under heavy load, need to spawn new processes and consuming more RAM, also creates new threads which have to compete for CPU and RAM resources;
  • Limit has to be set to ensure that resources are not overloaded, when the limit is reached, additional connections will be refused;
  • Limiting factor in tuning Apache: memory and potential to dead-locked threads contending for the same CPU and memory.

nginx:

  • Open source web server application written to address performance and scalability issues associated with Apache;
  • Event-driven, asynchronous and non-blocking approach, doesn’t create new processes for each web request;
  • Setting number of worker processes, and each worker can handle thousands of concurrent connections;
  • Modules are included at compile time, have internal PHP code compiler (no need for PHP module)

To conclude, nginx is faster and able to handle much higher load compared to Apache using the same set of hardware. However, Apache is still much better in terms of functionality and the availability of modules required to work with back-end application servers and to run scripting languages. So, it really depends on what you want to run on your web server. It is actually possible to run both Apache and nginx on the same server, so you can have the best of both worlds. For example, you can run nginx as reverse proxy while Apache is running in the back-end.

Advertisements