To install Linux, Nginx, MySQL, PHP (LEMP) in Ubuntu 14.04

By kedinn 2014/10/29

It will begin to share my knowledge on servants and this sera my first tutorial, where we will install Web server Nginx, data base Mysql and PHP.

This procedure is the same in debian.


Installation of Nginx

I sweat apt-get update
I sweat apt-get install nginx

If they want To install completes it stable version of nginx (they ignore the previous lines)

I sweat apt-get install python-software-properties

I sweat add-apt-repository ppa: nginx/stable

I sweat apt-get update

I sweat apt-get install nginx

Now we will see if it works correctly in its direction of domain or IP.


If it appears to you the following image all well this:)

to nginx_instalar

Installation of Mysql

Now we will install data base Mysql with in the following line.

I sweat apt-get install mysql-server


It will be asked for to him that it facilitates a password of root for MySQL.

The data base MySQL already is installed, but its configuration not yet is exactly complete.

First of all, we must tell him to MySQL that generates the structure of directories that needs to store to its information and data bases. We can do this writing:

I sweat mysql_install_db

Now with the following line we will request a security configuration that is optional but that it will serve us to assure the servant.

I sweat mysql_secure_installation

It will ask to him to introduce the password of root of MySQL that it has selected during the installation.

Next, it will be asked to him if it wishes to change the password. If you are happy with his password of root of MySQL, “N? writes for and does not beat “Enter?. later it will be requested to him that it retires some users of test and data bases. You only must press “ENTER? through these instructions to eliminate the predetermined configuration uncertain, does not worry but ahead she will be able to form Mysql according to what she wants.

Once finished in the end it showed to them that it was installed successfully!

Installation of PHP

Now we have Nginx as Web server and data base MySQL, continuation we install PHP.

From Nginx it does not contain the native processing of PHP as some other Web servers, we will have to install php5-fpm, which means “fastCGI process manager?.

We will begin with the following line:

I sweat apt-get install php5-fpm php5-mysql

It forms the PHP processor

Now we have installed PHP, but we must make a change of slight configuration to make our safer configuration.

It opens the configuration file of php5-fpm with the following line:

I sweat nano /etc/php5/fpm/php.ini

We look for in this file the line that contains cgi.fix_pathinfo if this commented the descomentamos by predetermined comes with a value 1, it change by 0, the line must be of the following form:


Now reiniciarremos our processor of PHP writing:

I sweat service php5-fpm restart

Until now we do not know if we are well, then we are going to form and to see if this works correctly.

Configuration of nginx

We are going to change some things to tell him to Nginx to use our processor of PHP for the dynamic content, something similar as Apache.

We enter the following file:

I sweat nano /etc/nginx/sites-available/default

and it would show to us as this:

server \ {lists 80 to default_server; they list [::]: 80 to default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; server_name localhost; location/\ {try_files $uri $uri/=404; }}

We must make a change and it must stay to us as this:

    server \ {lists 80 to default_server; they list [::]: 80 to 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_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; }}

We will reinitiate nginx:

I sweat service nginx restart

We will create a file info.php, this sera so that it shows all the facilities to us that we have

I sweat nano /usr/share/nginx/html/info.php

Now we insert this code php:

<? php phpinfo ();? >

and we kept Ctrl + x to leave and YES soon so that one keeps.

we open our navigator we will enter our direction with the name of domain or IP:


If this it showed to us all well of this form:


if they want to eliminate the file info.php is with the commando rm:

I sweat rm /usr/share/nginx/html/info.php



And ready! I hope that it serves to them and greetings:)