To install the LEMP (Linux, Nginx, MySQL, and PHP) stack on Ubuntu 14.04 LTS, you can follow these steps:
sudo apt-get update sudo apt-get install nginx
This will install the latest version of Nginx available in the Ubuntu package repository.
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.
sudo apt-get install php-fpm php-mysql
This will install PHP and the php-mysql
module, which allows PHP to communicate with MySQL.
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.
sudo service nginx restart sudo service php5-fpm restart
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.