LEMP is an open-source software stack (its name is derived from the popular LAMP stack that stands from Linux Apache MySQL PHP) only that in this case Apache web server component is replaced with nginx (pronounced "engine x," providing the "E" in LEMP) to increase the ability of the server to scale in response to demand. This article we are using Ubuntu 14.04 version for installation and you could try on your vps or cloud servers.
Installing MySQL and PHP
Let's start by installing MySQL with support for PHP and the fast-cgi package. You can use the apt-get command to get the latest version of the packages from the repository:
$ sudo apt-get install mysql-server php5-mysql php5-fpm
Nginx (pronounced engine-x) is a popular free, open-source, high-performance HTTP server and reverse proxy. Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption. Nginx is one of a handful of servers written to address the C10K problem and instead it doesn't rely on threads to handle requests, it uses a much more scalable event-driven architecture. This architecture uses small, but more importantly, predictable amounts of memory under load.
Nginx is available on most Linux distribution, so you can easily install it from the repository, on Debian/Ubuntu based systems you can install it using the following command:
$ sudo apt-get install nginx
Next we will have to configure nginx to work with MySQL and PHP, to do this you will have to modify the "/etc/nginx/sites-available/default" file using your favorite text editor. First you will need to add "index.php" to the index (marked with blue), next change the server_name directive to your own domain name, we used linoxide in this example (marked with green) and finally uncomment the PHP section by removing the "#" in front of the code (marked with yellow). The file should look something like this:
After you finish editing the config file you will have to reload nginx using the following command:
$ sudo /etc/init.d/nginx reload
Now you can use your favorite browser to access the newly installed nginx server by pointing to the server domain name or IP address.
WordPress is a free and open source blogging tool and a content management system based on PHP and MySQL. It is by far the most used blogging platform in the world and one of the most used CMS today. WordPress was used by more than 22.0% of the top 10 million websites as of August 2013.
Installing WordPress is easy, first you will have to download the package from the WordPress Download Section in the nginx directory using with wget like this:
$ cd /usr/share/nginx/html
$ sudo wget http://wordpress.org/latest.tar.gz
$ sudo tar zxvf latest.tar.gz --strip-components=1
Then using the sudo command set the permissions so you will be able to modify the files and allow the web server to access them as well like this:
$ sudo chown -R lemp276 *
$ sudo chgrp -R www-data *
Next we will have to create a database and username for our WordPress installation, to do so follow the next steps:
Note: This will create a database named wordpress with a username named wordpress and the password "foopassword", you can use your own database names and you will have to use your own password.
$ mysql -u root -p
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost" IDENTIFIED BY "foopassword";
mysql> FLUSH PRIVILEGES;
Rename the wp-config-sample.php file to wp-config.php and using your favorite text editor you will need to add the name of your database, mysql username and password to the config file, it should look like this:
You can now go to your favorite browser and use your IP or hostname to access the new WordPress installation, it will ask you for the website name and the username you want to use with WordPress:
After you finish with that it will quickly setup WordPress:
Now you will just have to use your WordPress username and password to log in:
It will point you to your freshly installed WordPress running on nginx:
Congratulations you now have a fully working installation of WordPress on the LEMP stack.