Nginx Installation

Nginx packages are available under default repositories. SSH to your Ubuntu 18.04 LTS system with sudo privileges account and install Nginx web server from the official repository.

PHP Installation

For the PHP installation we recommend to use ppa:ondrej/php PPA, which provides latest PHP versions for Ubuntu systems. Use the below couple of commands to add the PPA to your system. Then install PHP 7.3 the latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages. After installing above packages php7.3-fpm service will automatically be started. You can make sure by typing below command on terminal.

Nginx Configuration

Let’s create a Nginx virtual host to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost. Use the below basic Nginx Virtual host configuration with php fpm settings. Update the configuration as followings.

Save your changes to the configuration file and create a link to site enabled directory. Then restart Nginx service to reload the changes.

Test Setup

Create a PHP script with phpinfo() function and place it to your server document root. Use below command to do it. Now access the info.php using server IP address (for default VirtualHost) for your configured domain in Nginx VirtualHost.

Slide down the page and see the value of $_SERVER[‘SERVER_SOFTWARE’]. This will the show the web server details.

Conclusion

You have successfully configured Nginx web server with PHP-FPM on your Ubuntu 18.04 (Bionic) LTS. You can now host a website from your server.

How to Install Nginx with PHP FPM on Ubuntu 18 04 LTS   TecAdmin - 66How to Install Nginx with PHP FPM on Ubuntu 18 04 LTS   TecAdmin - 65