Nginx is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows you how to install Nginx on a Linux mint 18 with PHP support (through PHP-FPM) and MySQL support. PHP-FPM is an alternative PHP FastCGI implementation. It has some additional features useful for sites of any size, especially busier sites).

Install MySQL:

First, we will install the MySQL by issuing the following command. You will be asked to create MySQL admin password.

Open a web browser and visit http://your-ip-address, you should see the following page; this will confirm you that the Nginx is successfully installed on the server.

Linuxmint 17 – Nginx Default Page

The default nginx document root on Linuxmint 17 is /usr/share/nginx/html/. The configuration files are under /etc/nginx directory.

Install PHP5-FPM:

Next is to install PHP through PHP-FPM (PHP-FPM (FastCGI Process Manager), it is an alternative PHP FastCGI implementation. it has some additional features useful for sites of any size, especially busier sites). Install it by issuing the following command.

$ sudo apt-get install php5-fpm php5-mysql php5-cli

Edit /etc/php.ini.

$ sudo nano /etc/php5/fpm/php.ini

set cgi.fix_pathinfo=0

cgi.fix_pathinfo=0

Edit /etc/php5/fpm/pool.d/www.conf file,

$ sudo nano /etc/php5/fpm/pool.d/www.conf

Make sure the following values are UN-commented.

listen = /var/run/php5-fpm.sock

EnablePHP-FPM Support on Virtual Host:

Let’s create name based virtual host on Nginx server for the following details.

Testing PHP-FPM support on the Virtual host:

For testing the PHP, Place one PHP file on to the document root of the created virtual host, In the terminal copy/paste the following line:

# vi /usr/share/nginx/html/itzgeek.com/index.php

This will open up a file called index.php, Copy/Paste this line into the index.php file:

<?php phpinfo(); ?>

Save and close the file.
Restart the services.

$ sudo service nginx reload
$ sudo service php5-fpm reload

Now open up your web browser and type your domain in the web address:

http://server.itzgeek.com

The page looks like below:

Linuxmint 17 – PHP5-FPM support

From the above screen shot, PHP is working, and it’s working through FPM/FastCGI, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP.
Scroll down the browser and look for the MySQL support information.

Linuxmint 17 – Nginx MySQL support

Extras:

If you get any error related to permission denied like below on /var/log/nginx/error.log, you need to follow below steps