Nginx, MariaDB, PHP And phpMyAdmin installation

LEMP Installation (Nginx, MariaDB, PHP And phpMyAdmin) on Ubuntu 14.04 in 4 steps

A combination of Linux based operating system and open-source software stack, LEMP provides a LAMP compatible platform for all applications. The acronym LEMP stands for Linux, Nginx (engine-x) HTTP Server, MySQL/MariaDB database and PHP/Perl/Python. A key distinguishing factor between LEMP and its predecessor LAMP is the replacement of the Apache Server with nginx ( pronounced “engine x”) in LEMP , which has made the server more scalable in response to high demand situations. Meanwhile you have an option to replace MySQL with MariaDB, a more scalable and robust SQL server with multiple enhancements.

Here's a look at how I configured a LEMP server on Ubuntu 14.04.

Step 1: Install Nginx

Install nginx using command :

sudo apt-get install nginx

Start Nginx service using the command:

sudo service nginx start

Open up web browser and navigate to http://ip-address/ or http://localhost/. See a screen with message Welcome to Nginx!

# Nginx Configuration:

Open the file /etc/nginx/nginx.conf  and enter the following command in terminal

sudo nano /etc/nginx/nginx.conf

Set the worker_processes To see the no. of CPU’s, use the command “lscpu”. In my case it’s “4″. So I set this as ’4′.

worker_processes 4;

After that Restart the Nginx Services :

sudo service nginx restart

The default vhost (server block) is defined in the /etc/nginx/sites-available/default file.

Under the Server section, as shown below add index.php line.

server {
      listen 80 default_server;
      listen [::]:80 default_server ipv6only=on;
      root /usr/share/nginx/html;
      index index.php index.html index.htm;
      # Make site accessible from http://localhost/
      server_name server.unixmen.local

Under the section #location ~ \.php$. Uncomment and modify the following lines as shown below.

location ~ \.php$ {
         try_files $uri =404;   ---------> Add this line
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
         #       # With php5-cgi alone:
         #         fastcgi_pass;
         #       # With php5-fpm:
         fastcgi_pass unix:/var/run/php5-fpm.sock;
         fastcgi_index index.php;
         include fastcgi.conf;

Added an extra line ‘try_files $uri =404;’ to prevent zero day exploits.

# Test Nginx configuration

Test the nginx configuration for any syntax errors using command:

sudo nginx -t

Sample output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally restart nginx service

sudo service nginx restart

Step 2 : Install MariaDB!

A drop in replacement for MySQL and a reliable SQL server, MariaDB comes with a rich set of enhancements that makes it more robust and scalable.

# For Installing MariaDB enter this command in the terminal.

sudo apt-get install mariadb-server mariadb-client

During installation set database ‘root’ user password set password.

# Check the MariaDB version using command:

sudo mysql -v -u root -p

# Check if MariaDB is running or not, using the following command:

sudo service mysql status

Step : 3 Install PHP

PHP (recursive acronym for PHP: Hypertext Pre-processor) is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

# Install php5-fpm

sudo apt-get install php5 php5-fpm php5-mysql

# Configure PHP

Open php.ini file in any editor:

sudo nano /etc/php5/fpm/php.ini

Find the line ‘cgi.fix_pathinfo=1′, uncomment it and change the value 1 to 0.


Now restart php-fpm service.

sudo service php5-fpm restart

# Test if PHP is running or not.

Create a sample “info.php” file in nginx document root folder.

sudo nano /usr/share/nginx/html/info.php

Add the following lines in it.

Save and exit the file.

PHP-FPM listens on the socket /var/run/php5-fpm.sock by default. To make PHP-FPM use a TCP connection, open the file /etc/php5/fpm/pool.d/www.conf,


sudo nano /etc/php5/fpm/pool.d/www.conf

Find the line listen = /var/run/php5-fpm.sock,

;listen = /var/run/php5-fpm.sock

and modify it to listen =

listen =

Save and exit the file. Restart php5-fpm service.

sudo service php5-fpm restart

Now open the nginx configuration file:

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

Find the line fastcgi_pass unix:/var/run/php5-fpm.sock; and change it to fastcgi_pass; as shown below.

location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_pass;
        #         # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #         # With php5-cgi alone:
        #     # With php5-fpm:
        #         fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi.conf;

Save and exit the file.Now Restart nginx service.

sudo service nginx restart

# Manage Databases Using phpMyAdmin 

phpMyAdmin is a free open-source web interface tool used to manage your databases.

Step 4 : Install phpMyAdmin

Install it with command:

sudo apt-get install phpmyadmin

The phpMyAdmin installation has been completed.

Create a symbolic link between phpMyAdmin and the website root directory. Here our website root document directory is /usr/share/nginx/html/.

sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/html

Restart nginx server again

sudo service nginx restart

Now manage your databases from phpMyAdmin web interface.

That’s it. LEMP server is now up and ready to use.

We at Valuebound are committed to furthering your business initiatives with our Enterprise level web solutions. For further information on our service offerings, please Contact us.