How to install Nginx, PHP, PHP-FPM and MYSQL from source to run a wordpress site on Ubuntu 16.04

Many Linux package managers have built in packages for nginx, php and mysql, they are good if you have less experience with Linux, but installing from source will give you more control our installation locations, settings and much more. So today we will see how we can install Nginx and PHP-FPM (from source) and mysql from the package manager and finally run the word press site. I am going to use Ubuntu 16.04 server distribution.

Step 1: Download and install Nginx!

The first thing we are going to do is install our web server (Nginx). I am going to put all the downloads in one separate folder so that we can keep things organized.

To solve Nginx dependencies run:

Create folder, download and install the source

Now you can run nginx using

Open your favourite browser and enter “localhost” in the address bar, and you will see something like this.


Our webserver is now installed and ready to use.

Step 2: Install MYSQL

Before installing PHP-FPM, we need to install mysql, because it is required for word press installation to work, you can install mysql using:

Our mysql installation has now completed.

Step 3: Install PHP-FPM

At the time of writing of this article, PHP 7 has been released, so I will be installing php7 with php-fpm. You can download PHP from available mirrors located at :

After running the last command above, you will have some output printed out on terminal, something like this :

These are paths to your php files, for later reference please save them at a safe place, now our PHP is installed and we are ready to use php-fpm.

Step 4: Configure PHP and PHP-FPM

We need to make some adjustments before we can start using PHP-FPM, you can download our configuration files from cyberperson mirrors.

Now all your configuration files are downloaded (If for some reason you are not able to download the configuration files, please comment). Its time you should start your PHP-FPM so that you can start using php. Run the following to start PHP-FPM

We have to configure NGINX and add virtual host for our domain,  so that we can run a wordpress site.

Step 4: Configure Nginx

In the NGINX configuration file you have to configure virtual host, that will host your wordpress site. If you have installed nginx on the same prefix as we did, than your configuration file for nginx will be located at “/usr/local/nginx/conf” with name “nginx.conf”.

Inside your “HTTP” block paste the following

In front of server_name, replace domain with your actual domain name. Now we’ve to create a directory to host content for our domain.

Step 5: Create Database

Before we head towards the installation of wordpress, we need to create mysql database. Use  following commands to create database, and add user to it.

If you have used above commands, your database credentails will be

  • Database name : wp
  • Database user : wp
  • Database password : cyberpersons
  • Host : localhost

Step 6: Reload Nginx and Install wordpress

If you have nginx already running, you can reload the configuration (because we have modified nginx configuration)

Once nginx is reloaded, you can visit your domain, but please make sure you have already properly setup-ed DNS for your domain, to set DNS you can visit a link here. Once DNS is set you can visit your domain in the browser, in our case domain is “”.

If everything worked correctly you might see something like this:


Just click “Lets Go”, and then enter your database details, and you are ready to use wordpress. 🙂

2 thoughts on “How to install Nginx, PHP, PHP-FPM and MYSQL from source to run a wordpress site on Ubuntu 16.04

  1. Why did you not include also the setting below? Other tutorial that I found on web, have it.

    # regex to split $uri to $fastcgi_script_name and $fastcgi_path
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    # Check that the PHP script exists before passing it
    try_files $fastcgi_script_name =404;

    # Bypass the fact that try_files resets $fastcgi_path_info
    # see:
    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.