PART 2: Installing NGINX, MySQL and PHP on Ubuntu 16.04 Xenial Xerus

Since we are using Ubuntu 16.04, you don’t have to build NGINX from source to get the enhancements of 1.9+. Instead, you can install nginx using the sudo apt-get command below. This will install the package, with prebuilt configurations for nginx.

sudo apt-get install nginx -y

If you want to customize the configuration you should compile from source.  To compile and install from source, I highly recommend NGINX’s site for the full configuration options available.

Install php 7.0

PHP is rather straightforward to install, and optimization will be covered in another section.

sudo apt-get install php-fpm -y

PHP is rather straightforward to install, and optimization will be covered in another section.

sudo apt-get install php-fpm -y

Install MySQL 5.7

Note: There are two different versions readily available in the repositories, make sure you install 5.7, unless you are looking for an older version on purpose.

sudo apt-get install mysql-server-5.7 -y

You will be prompted to create a root password for MySQL.  It is normally a VERY good idea to password protect your MySQL database.  I don’t mean some silly short and easy password, I mean a serious password! MySQL can easily be the keys to your server, if left unsecured.  After you have finished installing MySQL, let’s check to make sure everything is the correct version and running.

nginx -V


This should look like the example below:

This tells you not only the version of NGINX, but also all of the configuration arguments used for building.  Note: HTTP2 (which is replacing SPDY) only works with certain encryption methods in SSL, so some additional configuration will be required to utilize HTTP2.  That will be covered later. Next let’s check php

php -v

This should read something like


For MySQL, you have to actually enter the MySQL CLI to get the information

mysql -u root -p

to show something like:


To exit:


Time to check it out in your browser.  If you are running a DNS server, you can go ahead and enter your hostname into the records so that you can resolve the ip.  Enter the ip address in your browser:


Now to check that PHP is working correctly we are going to edit a couple of files.

Using your preferred text editor (ie. vim or nano)



Add index.php to index index.html index.htm index.nginx-debian.html;

making it index index.php index.html index.htm index.nginx-debian.html;

you also need to uncomment the php location (I prefer to remove non-relevant lines as well) , allowing php to be executed server side so that it looks like this


save and quit, then reload NGINX.

sudo service nginx restart

Now to ensure that PHP is being executed we need to add the file index.php



Refresh your browser and you should see a page detailing your php setup.

You don’t want to leave this information up when you have a live site, so either delete the file now, or when you are ready.

Time to point your domain (provided you have one) to your server. If you don’t know your ip, my favorite way to find it is


if you are using ipv6

curl -6

Update the address with your domain name provider or domain name server, and you should be able to bring up the default site using your domain (as soon as the information is updated).

To update your site, time to build your site conf file (replace with your domain).

Tip: “error_page 404 = /index.php” lets the server redirect to index.php rather than a standard 404 error page.  The error log is unable to used a regular expression, and who really wants to search all over for problems anyway.  Hence, no $server_name to separate out the error logs.

2016-05-16_115612You can also install SSL for free on nginx. click (here)

Justin Henneberg
Justin is a long time Linux Admin, with extensive experience breaking systems – serious fun in tweaking 'til you kill it. If you break enough systems you can fix just about anything. A little nefarious fun adds the element of knowing how to help harden against security threats. Add a bit of hardware design, and you have the recipe for fun. Always remember “All electronics run on smoke. If you let the smoke out, they stop running.”

Expert Tip

PART 2: Installing NGINX, MySQL and PHP on Ubuntu 16.04 Xenial Xerus

If the issue is with your Computer or a Laptop you should try using Restoro which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Restoro by clicking the Download button below.

Download Now

I'm not interested