A LEMP stack is defined as a stack of software applications which basically means: Linux, NginX, MySQL and PHP. Unlike LAMP stacks (Apache instead of NginX), LEMP stacks aren’t built into Linux distributions yet. If you want a LAMP stack, you can just install it with apt-get install lamp on Debian-based distributions (including Ubuntu and Linux Mint). If you want a LEMP stack, you have do it one step at a time.
This is the first letter of LEMP and the most important. Choosing a good Linux distribution as the operating system is paramount. If the underlying architecture has problems, everything you add will have problems. Fortunately, there are several distributions that will do the job nicely.
I can’t say which distributions are the best, but I’ve worked with Debian, Ubuntu (based on Debian) and CentOS and so far, I like Ubuntu the best and that’s what I’m referencing from here on out.
I won’t tell you how to do it. Instead, read how to install NginX on Ubuntu 10.04 64bit via apt-get. That’s how I did it the last time. I’m sure 12.04 (the latest version of Ubuntu) would be done the same way.
While I’m at it, I should probably tell you the easiest way to add or remove virtual hosts. I found a BASH script, Nginx-manager: A tool for managing Nginx on Ubuntu/Debian Linux., and I’ve been using it since the first day I started working with my current server.
It’s really simple to install: apt-get install mysql-server. The hard part is configuring it for your particular needs. I won’t get into that right now, but MySQL will work upon installation without any changes.
What you really want is PHP-FPM because NginX uses processes, not events. I previously explained installing and configuring PHP and PHP-FPM on Ubuntu 10.04 64-bit LTS, but it should also work up to version 12.04.
I have an older point version in the 5.3 series installed and I may soon be upgrading to the 5.4 series using this method.
After the LEMP Stack is Installed
It doesn’t take long to get a LEMP stack up and running on an Ubuntu server. What takes time is adjusting the configurations for each component and adding things that complement them, like APC.
When you make changes, you need to restart or reload the appropriate component as a service. Let’s use “restart” in these examples:
- service nginx restart — use nginx -t to test your configuration changes before using reload or restart. Most of the time, “reload” is all that’s necessary.
- service mysql restart
- service php-fpm restart
I don’t know about the others, but restarting PHP-FPM is done in a “graceful” manner. This comes in real handy when you’re changing and testing changes made in the php.ini file.