Skip to content
TrySitePrice

Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS

Best/Tutorial

Here's how you can install the LEMP (Linux, Nginx, MySQL, and PHP) stack on an Ubuntu Linux 14.04 LTS server:

  1. Update the package repository:
sudo apt-get update
  1. Install Nginx web server:
sudo apt-get install nginx
  1. Start Nginx and enable it to start at boot:
sudo service nginx start
sudo update-rc.d nginx defaults
  1. Install MySQL server:
sudo apt-get install mysql-server
  1. Start MySQL and enable it to start at boot:
sudo service mysql start
sudo update-rc.d mysql defaults
  1. Install PHP:
sudo apt-get install php5-fpm php5-mysql
  1. Configure Nginx to use PHP:
sudo nano /etc/nginx/sites-available/default

Edit the default server block to look like this:

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 localhost;

 location / {
 try_files $uri $uri/ /index.html;
 }

 location ~ \.php$ {
 fastcgi_split_path_info ^(.+\.php)(/.+)$;
 fastcgi_pass unix:/var/run/php5-fpm.sock;
 fastcgi_index index.php;
 include fastcgi_params;
 }
}

  1. Restart Nginx and PHP-FPM:
sudo service nginx restartrnsudo service php5-fpm restart

After these steps, you should have a working LEMP stack on your Ubuntu Linux 14.04 LTS server.