More and more webmasters are moving away from the traditional LAMP stack to host their web applications.

Few years ago, the default LAMP stack was always, Linux, Apache2, MySQL and PHP.

Today, many are supporting other servers and packages to run their blogs and web applications.  For example, instead of running Linux, Apache2, MySQL and PHP, some are installing Linux, Nginx, MariaDB and PHP instead.

Few days ago, we showed you how to install the traditional LAMP stack using Ubuntu server.

That post can be viewed by clicking this link.

Those webmasters who want to go with Linux, Nginx MariaDB and PHP instead can continue below.

This post shows you how to install what others called the LEMP stack. To continue with this setup, you must be running Ubuntu server and have root access to it.

To get started, the first thing you’ll want to do is install Nginx web server. Nginx is a powerful, fast and lightweight web server.

To install Nginx, run the commands below.

sudo apt-get install nginx

After installing Nginx, use the commands below to start, stop and enable it to always start up after rebooting your server.

sudo systemctl enable nginx.service
sudo systemctl stop nginx.service
sudo systemctl start nginx.service

Next, go and install MariaDB database server. MariaDB database server can be a direct replacement for MySQL database server.

To install MariaDB database server using Ubuntu, run the commands below.

sudo apt-get install mariadb-server mariadb-client

After installing MariaDB, use the commands below to start, stop and enable it so that it automatically start up after your server reboots

sudo systemctl enable mysql.service
sudo systemctl stop mysql.service
sudo systemctl start mysql.service

The next thing to do after running the commands above is to run this command to configure MariaDB server.

sudo mysql_secure_installation

Next, choose Yes (Y) for the rest of the prompts until you’re done.

  • Enter current password for root (enter for none): Press Enter for none.
  • Set root password? Y
  • Create and confirm a new password
  • Remove anonymous users? Y
  • Disallow root login remotely? Y
  • Remove test database and access to it? Y
  • Reload privilege tables now? Y

Finally,  run the commands below to install PHP5 and other PHP5 modules to supporting PHP scripts.

sudo apt-get install php5 php5-fpm php5-mysqlnd php5-curl php5-gd php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-sqlite php5-tidy php5-xmlrpc php5-xsl

This is how one installs the LEMP stack.. The next thing is to verify your installation and make sure these servers are installed correctly and functioning.

First, configure Nginx to enable PHP support. To do that, open Nginx default server configuration file.

sudo vi /etc/nginx/sites-available/default

Then edit ( add/modify) the highlighted lines shown in the code below.

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
#
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
#
root /var/www/html;
#
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
#
server_name _;
#
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
#
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
#
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

Save the file then reload Nginx web server by running the commands below.

sudo systemctl reload nginx.service

To test Nginx all you have to do is open your web browser and browse to the server IP address or Hostname. If you see Nginx default server page, then Nginx is functioning.

nginx virtual host

To test functionality, create a small PHP file using the script below.

sudo vi /var/www/html/test.php

Then add this content to it and save it.
<?php
phpinfo();
?>

Save it and browse to it from your browser and you should see PHP test page.

apache-nginx-ubuntu-1.png

MariaDB database server can be testing by running the commands below.

sudo systemctl status mysql.service

Enjoy!