Installing nginx and PHP7.2 on Ubuntu 18.04

Before you’re going mad about this unintelligible so-called tutorial, let me clarify that this post is not a fairy story about a successful installation. Instead, it falls into my favorite WordPress category : fail:reconstructed.

Ubuntu 18.04

By the time of writing, I had never successfully installed Ubuntu 18.04 from fresh, daily-build .iso you usually get from Ubuntu official page. Meanwhile, this post is written on a Firefox browser, running on Ubuntu 18.04 inside a box of Oracle’s VirtualBox. How did I get here?

My first trial on installing Bionic Beaver was by downloading the daily build iso and shoving it into a VM box. It was installed successfully, allowed me to see the first sight of its GNOME theme and the removal of app menu in Firefox. The problem is I can never get past the boot screen next time I restart the VM (that SO post isn’t mine tho, but glad to see I’m not the only one).

My second trial was downloading more recent iso (differs by 1 day from my first trial). The problem persisted.

My third trial was installing a fresh 16.04, apt update && apt upgrade it to the latest package, then Alt+F2 and launch the update-manager -d to check whether there’s an available option to upgrade to 18.04. And there it was :

My previous configuration used kambing repository for speed reason. Alas, it failed to provide some files necessary to run the upgrade process :

Changing repository to us.archive.ubuntu.com solves the problem. The upgrade process ran smoothly and here I am writing this post on a restart-able Bionic Beaver.

Nginx

Ubuntu 18.04 Bionic Beaver ships with default nginx package version 1.13.x .

Use -s option to simulate an installation of packages

Done installing nginx, let’s take a look at our localhost to check whether nginx has been installed properly. If everything works fine and the nginx server has started, you should see an unmistakably similar page like the capture below.

PHP 7.2

We can install PHP7.2 directly from Ubuntu repository, without the need of adding Ondrej’s PPA.

Simulating installation of php7.2 package

Here comes the trick. If you want to deploy your PHP code and give nginx the right to handle PHP files, do not apt install php7.2

This is what gonna happen if we persist in installing php7.2 package. As you can see in the simulation above, it will install apache2 packages as well. Since we intend to use nginx as our web server, these apache2 packages will never be used, and instead will interfere with our previous nginx configurations. First, you will see that localhost page now shows apache2 welcome page :

“Oh, no worries, let’s just shut down the apache service and start the nginx” – maybe that’s what comes into our mind. Actually, at this moment the apache service is not even started, and the Apache2 Ubuntu Default Page shown above is actually an HTML file (/var/www/html/index.html) served by nginx service (which is still running).

TL;DR

If you just want to have nginx as your web server to serve PHP files from your web root, only install php-fpm package (php7.2-fpm and its required packages). It will serves you right out of the box, without hassling over apache-nginx conflict, and of course it has a smaller footprint.

 

This entry was posted in fail : reconstructed. Bookmark the permalink.

Comments are closed.