Install Nginx, PHP, Mysql on Ubuntu 16.04

Steps to install Nginx, PHP 7, Mysql 5 in ubuntu 16.04:

Step 1: Install the Nginx Web Server

sudo apt-get install nginx

check the ngnix is start, by calling below url in browser


Note: Nginx default use the 80 port, hence if you apache install then change the port for ngnix

Step 2: Install MySQL

sudo apt-get install mysql-server

set password to the mysql as prompted

Step 3: Install PHP

sudo apt-get install php-fpm php-mysql

Configure the PHP processor

execute below command to edit php.ini

sudo nano /etc/php/7.0/fpm/php.ini 

set parameter in PHP.ini


Run below command to restart the php-fpm

sudo service php7.0-fpm restart

Step 4: Configure Nginx to Use the PHP

Edit below file:

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

add index.php file after index line and remove comment  below PHP code

# pass the PHP scripts to FastCGI server listening on the php-fpm socket

 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;

And restart the nginx using

sudo service nginx restart

Step 5: Create a PHP File to Test Configuration

Create file in root directory

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

put php tag and “phpinfo()” function

Run file with browser as below


For more details my Youtube channel link for “Install Nginx, PHP, Mysql on Ubuntu 16.04”

That’s all for “Install Nginx, PHP, Mysql on Ubuntu 16.04” , we may interested for install frameworks, go below link

  >> Install Laravel 5 via composer

Leave a Reply

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