With the release of the new version of Ubuntu, version 19.04, code-named Disco Dingo, we thought it would be nice to go over how to install one of the more popular web development stacks which people tend to use. The Nginx, PHP, MySQL stack.

Nginx which is actually pronounced as “engine x” 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 how you can install Nginx on an Ubuntu 19.04 LTS also known as Disco Dingo with PHP 7 support (through PHP-FPM) and MySQL support (LEMP = Linux + nginx (pronounced “engine x”) + MySQL + PHP).

Step 1 – Update repository and Install Nginx

Nginx or engine x is a high-performance HTTP and proxy server with low memory consumption. Most large-scale websites like Facebook, Netflix, Pinterest, CloudFlare, GitHub are using Nginx. In this step, we will install Nginx web server from the Ubuntu repository.

sudo apt-get update
sudo apt-get upgrade
sudo apt install nginx -y

After the installation is complete, start the Nginx service and enable it to launch every time at system boot.

systemctl start nginx
systemctl enable nginx

At this point, we have successfully installed Nginx and as such you will be able to access the static page from the web interface

Step 2 – Install MySQL

MySQL is the most popular open source Relational Database Management System (RDBMS) created by Oracle Corporation. It’s a central component of the LEMP Stack, and we will install the latest MySQL version from the Ubuntu repository. Install MySQL using the apt command below.

sudo apt install mysql-server mysql-client -y
systemctl start mysql
systemctl enable mysql

After the MySQL installation is complete, the last two commands allow us to start the MySQL service and enable it to launch every time at system boot. After this step, we’ve installed MySQL 5.7 on Ubuntu 18.04 server.

Step 3 – Install PHP-FPM

PHP-FPM or FastCGI Process Manager is an alternative for the older PHP FastCGI which provides additional features and speed improvements. It suits well for small to large sites based on the PHP programming language. In this step, we will install PHP7.2-FPM with some additional extensions required by any php application. Install PHP-FPM using the command below.

sudo apt install php7.2 php7.2-fpm php7.2-cli php7.2-curl php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php-pear -y
systemctl start php7.2-fpm
systemctl enable php7.2-fpm
netstat -pl | grep php

The last two commands allow the PHP-FPM service and enable it to launch every time at system boot after all installation is complete. PHP7.2-FPM is up and running on Ubuntu 18.04 under the sock file, check it using the netstat command.

Step 4 – Configure Nginx and PHP-FPM

In this step, we will configure the Nginx web server and PHP-FPM. Go to the /etc/nginx configuration directory, and edit the ‘nginx.conf’ file using vim.

cd /etc/nginx/
vim nginx.conf

Uncomment the following lines.

keepalive_timeout 2;
server_tokens off;

Save the configuration file and exit the editor. Now edit the default Nginx virtual host file.

vim sites-available/default

Uncomment the PHP line shown below and change the sock file line.

 location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        # # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        # # With php-cgi (or other tcp sockets):
        # fastcgi_pass;

Save and exit. Test Nginx configuration and make sure there is no error, then restart the service by using the commands below

nginx -t
systemctl reload nginx

Test your installation

Our LEMP stack should now be completely set up. You can test it to validate that Nginx can correctly hand .php files off to the PHP processor. To do this, use your text editor to create a test PHP file called info.php in your document root:

sudo vim /var/www/html/test-info.php

Enter the following lines into the new file. This is valid PHP code that will return information about your server: <?php phpinfo(); When you are finished, save and close the file. Now, you can visit this page in your web browser by visiting your server’s domain name or public IP address followed by /test-info.php:


You should see a web page that has been generated by PHP with information about your server: With that, you now have a fully-configured and functioning LEMP stack on your Ubuntu 19.04 server. Feel free to leave your questions and comments below.

The Calendarific blog is a knowledge-sharing platform built around a community of developers. We aim to make our readers’ go-to source for all things tech-related. If you are interested in contributing, we are happy to discuss. Please submit all inquiries info@calendarific.com. And if you enjoyed this post, we recommend reading our latest featured stories on the blog.

API icon

Start using our Holiday API

Use our Holiday data in your applications programmatically. No credit card is required to start.