Share this page:
A LEMP server consists of Linux Nginx, MySQL PHP. This is an alternative to the LAMP server which is built around Apache. Nginx has performance advantages, and uses less memory than Apache.
PHP APC is used to speed up the execution of PHP scripts. When PHP code is executed, it is usually compiled on the fly into byte code. PHP APC caches the byte code so that the next time the same PHP code is executed, it has been pre-compiled.
PHP scripts often use databases to store information. In a LEMP stack, it's common to use MySQL.
First, make sure your server is up to date by installing updates:
Install the following packages:
This command installs the MySQL client and server. The client doesn't have to be installed, but it's useful during development.
When the MySQL server is installed, you will be prompted to enter a password for the root user account. You need to enter it a second time to confirm the password. Make a note of the password as you'll need it later when you connect to the server.
On some ditributions, Nginx doesn't start automatically when it's installed, so you need to start it with this command:
Check that Nginx is working by opening a web browser and visiting your server's IP address. You should see this page:
The Nginx virtual host file needs to be modified to enable support for PHP. Open /etc/nginx/sites-available/default in nano:
Look for the index directive, and add index.php:
Next, look for the location that manages requests for PHP page. By default it is commented out.
This location needs to be un-commented, and one of the fastcgi_pass directives needs to be deleted. If PHP FPM is installed, the first fastcgi_pass should be deleted. The PHP location should now look like this:
Type control-o and press return to save the file, and type control-x to exit nano. Restart Nginx:
Test that PHP is working. Create a simple PHP test file:
Enter this text, and save the file:
Type control-o and press return to save the file, and type control-x to exit nano. Now visit the new page in your web browser by visiting http://server IP address/test.php. In my case this is http://192.168.1.50/test.php. You should see a page like this:
There are some adjustments that can be made to the MySQL server to make it more secure. The mysql_secure_installation utility will guide you through these steps, by asking a series of questions. The first one is whether you want to change the root password - answer no because a root password is already set. Answer yes to all the other questions:
Your LEMP server is now up and running. You can use it to develop PHP applications or run a PHP CMS like Wordpress.