Most of you might have heard about the LAMP stack, but there is a new web development stack model! The LEMP stack!
The difference between LEMP and LAMP is Nginx replacing the Apache web server. Most, of you, might be thinking why LEMP and not LNMP, it’s because Nginx is pronounced as Engine-X.
Nginx has become a delivery platform for the modern web, and many websites have already replaced Apache servers with Nginx reason being it has a load balancer that optimizes the availability of apps and APIs. The Content is cached, and web interaction is accelerated by the use of edge and local origin servers. It can easily stream and control high-quality media on any device. Monitoring and management of the website have become advanced.
Today around 140 million websites are using the Nginx platform for web development. The recently updated version of Nginx is Nginx Plus, which provides enterprise-ready features that give users the ultimate freedom to innovate without constraints.
We believe that you are already using the Linux Platform so we shall be skipping Ubuntu installation.
Nginx installation
Step 1
Initially, we shall update the Ubuntu apt repository before Nginx server installation.
$ sudo apt-get update
Step 2
Install nginx using this command
$ sudo apt-get install nginx
Nginx will be installed at /usr/local/nginx. You can make changes there.
Now, you need to check if Nginx is completely configured and is ready for further use.
Step 3
Use the commands below to find your server’s public IP address
$ sudo ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s//.*$//’
The result of this command is
111.111.111.111
fe80::601:17ff:fe61:9801
This command will display your current IP address.
Use the lines received as output in the web browser and it shall open the Nginx default page :
http://server_domain_name_or_IP
MySQL Installation
SQL stands for Structured Query Language. MySQL is one of the most powerful, reliable and ease to use database option for web-based applications, it is used by many websites like Facebook, Twitter, Yahoo! MySQL is used for database management in web development, cloud, mobile and embedded application. Once you have installed MySQL on your device, you can easily use it for further database creations, add, insert, manipulate and use it according to your convenience.
Step 4
Install the MySQL-server
$ sudo apt-get install mysql-server
Step 5
Use the following commands to generate MySQL directory structure.
$ sudo mysql_install_db
Step 6
Secure MySQL. Here you can change the MySQL root password, grant access to user accounts, enable or disable logins outside the remove test databases and local host.
$ sudo mysql_secure_installation
Step 7
Login into MySQL and try creating a test database. Use the command below and enter your root user password.
$ sudo mysql -u root -p
Once you have entered the password you will be redirected to the mysql prompt.
PHP Installation
Heading towards the last step, installation of PHP. Here, we shall be installing PHP FPM . It stands for FastCGI Process Manager and is an implementation of the classical PHP fastCGI with some advanced process management, ability to use and work with different ports, groups, users, and environments. The new model provides standard output and standard error logging and an emergency restart in case of cache destruction and is highly useful for heavily loaded sites.
Installing PHP as the final step for LEMP stack.
Step 8
Use these commands to install PHP
$ sudo apt-get install php5-fpm php5-mysql
Step 9
Now, we need to configure the PHP Processor. Initially, open the php5-fpm config file.
$ sudo nano /etc/php5/fpm/php.ini
The result of this command is
cgi.fix_pathinfo=0
We have used here Nano’s Another Editor you may also use vim or vi to open the file.
Now, looking closely we need to change the settings of cgi.fix_pathinfo it has a semicolon ( ; ) in the beginning, which indicates the default value of an attribute. Here, it was previously 1 we have changed it to 0
Save and close the file.
Step 10
Now, restart the PHP service.
$ sudo service php5-fpm restart
After the installation of all the three services, the most important task is configuring Nginx to use the PHP processor installed.
Step 11
Open the Nginx Config file and make the following changes
$ sudo nano /etc/nginx/sites-available/default
The result of this command is
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name server_domain_name_or_IP;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Here, we have inserted a new line and set index.php as the first option for the index, this shall redirect to PHP files when required.
Also, change the server name to your IP address (the one we have received earlier example here we mentioned 111.111.111.111)
Uncomment the error lines as they will help you to understand the defects in the program if any.
Also, include the try_files for Nginx to avoid bad passes.
Now, you have successfully configured the LEMP stack, create a test PHP file to check it’s complete functionality.