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

w‮ww‬.lautturi.com
Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS

To install the LEMP (Linux, Nginx, MySQL, and PHP) stack on Ubuntu 14.04 LTS, you can follow these steps:

  1. Install Nginx:
sudo apt-get update
sudo apt-get install nginx

This will install the latest version of Nginx available in the Ubuntu package repository.

  1. Install MySQL:
sudo apt-get install mysql-server

During the installation process, you will be prompted to set a password for the MySQL root user. Make sure to choose a strong password and remember it, as you will need it later.

  1. Install PHP and the necessary PHP modules:
sudo apt-get install php-fpm php-mysql

This will install PHP and the php-mysql module, which allows PHP to communicate with MySQL.

  1. Configure Nginx to use PHP:

Open the Nginx configuration file in a text editor:

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

Find the server block and modify it as follows:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.php index.html index.htm;

    server_name _;

    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_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Save the file and exit the editor.

  1. Restart Nginx and PHP-FPM:
sudo service nginx restart
sudo service php5-fpm restart
  1. Test the PHP installation:

Create a PHP file in the document root of your Nginx server (/var/www/html):

sudo nano /var/www/html/info.php

Paste the following code into the file:

<?php
phpinfo();
?>

Save the file and exit the editor. Then, open a web browser and navigate to http://your_server_ip/info.php. This should display the PHP information page, indicating that PHP is working correctly.

Created Time:2017-10-29 22:08:48  Author:lautturi