Install LEMP Server (Nginx, MySQL or MariaDB, PHP And phpMyAdmin) On Ubuntu 14.10/14.04/13.10

LEMP is a combination of the operating system and open-source software stack. The acronym LEMP comes from the first letters of Linux, Nginx(engine-x) HTTP Server, MySQL database, and PHP/Perl/Python.

In this tutorial, let us see how to install Nginx, MySQL or MariaDB, PHP and phpMyAdmin on Ubuntu 14.10.

Install Nginx

Nginx (pronounced as engine-x) is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server written by Igor Sysoev.

To install Nginx enter the following command in your terminal:

Note: If you have already installed apache2 in your system, remove it first to avoid conflicts. To uninstall apache, run the following commands:

Now, install nginx using command:

Start Nginx service using the command:

Test nginx

Open up your web browser and navigate to http://ip-address/ or http://localhost/.

Configure Nginx

Open the file /etc/nginx/nginx.conf in any editor:

Set the worker_processes (i.e No. of CPU’s in your system). To see the no. of CPU’s, use the command “lscpu”. In my case it’s “1″. So I set this as ’1′.

Restart Nginx service:

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

Open the file /etc/nginx/sites-available/default in any editor.

Under the Server section, set the server FQDN or IP address as shown below. Make sure you’ve added aindex.php line.


  • listen 80; –> listen for ipv4
  • listen [::]:80 default_server ipv6only=on; –> listen for ipv6
  • root /usr/share/nginx/html; –> document root directory.
  • server_name server.unixmen.local; –> Server FQDN.

Now, scroll down further and find the section #location ~ \.php$. Uncomment and modify the following lines as shown below.

Here, I added an extra line ‘try_files $uri =404;’ to prevent zero day exploits.

Save and exit the file.

Test nginx configuration

Test the nginx configuration for any syntax errors using command:

Sample output:

Finally restart nginx service

Install MySQL

MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases, though SQLite probably has more total embedded deployments

During installation, you’ll be asked to setup the MySQL root user password. Enter the password and click Ok.

Now, MySQL server has been installed.

You can verify the MySQL server status using command:

Sample output:

Note: If you want to use MariaDB instead of MySQL, then follow the below steps.

Install MariaDB

MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that comes rich set of enhancements.

First you have to remove existing MySQL packages if any. To completely uninstall MySQL with configuration files, enter the following command:

Run the following command to remove unwanted packages.

After removing MySQL, run the following command to install MariaDB.

Alternatively, you can install it from MariaDB repository if you want to try most recent version of MariaDB. Run the following commands to add PPA. As of writing this, MariaDB PPA is not yet updated to Ubuntu 14.10. However, we can use the repository of Ubuntu 14.04 instead.

Update the software sources list and install MariaDB using following commands:

During installation you will be asked to set database ‘root’ user password.

You can check the MariaDB version using command:

Sample output:

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

Sample output:

Install PHP

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

Install PHP with following command:

Configure PHP

Open php.ini file in any editor:

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

Now restart php-fpm service.

Test PHP

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

Add the following lines in it.

Save and exit the file.

Navigate to  http://server-ip-address/testphp.php. It will display all the details about php such as version, build date and commands etc.

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

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

and modify it to listen =

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

Now open the nginx configuration file:

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

Save and exit the file. Finally restart nginx service.

Manage MySQL Databases Using phpMyAdmin (Optional)

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

Install phpMyAdmin

It is available in the Official Debian repositories. So install it with command:

Select any webserver. By default, nginx will not be displayed here. So, select apache or lighttpd, and we will link phpmyadmin to work with nginx webserver later.

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

Restart nginx server.

Access phpMyAdmin Web Console

Now you can access the phpmyadmin console by navigating to http://server-ip-address/phpmyadmin/ from your browser.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.