Would you like to learn how to install Nginx and PHP on a computer running Ubuntu Linux? In this tutorial, we are going to install Nginx and configure the server so support PHP pages.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Nginx 1.18.0
• PHP 7.4

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial – Install Nginx on Ubuntu Linux

Install the Nginx server and the required packages.

Copy to Clipboard

Add the following line in the Nginx configuration file.

Copy to Clipboard

In our example, we set the Nginx maximum upload size to 32 Megabytes.

Here is the file after our configuration.

Copy to Clipboard

Restart the Nginx service.

Copy to Clipboard

The Nginx server was installed successfully.

Tutorial Nginx – Enable the PHP support

Nginx needs an external program to add PHP support.

Install the PHP package.

Copy to Clipboard

Install other PHP modules.

Copy to Clipboard

Find the location of the PHP configuration file on your system.

Edit the configuration file named: PHP.INI.

Copy to Clipboard

Your PHP version may not be the same as ours.

Your PHP configuration file location may not be the same as ours.

Enable and configure the following items of the PHP configuration file.

Copy to Clipboard

In our example, we are using the timezone of Brazil.

Edit the Nginx configuration file for the default website.

Copy to Clipboard

Enable the PHP support for Nginx.

Here is the original file, before our configuration.

Copy to Clipboard

Here is the new file with our configuration

Copy to Clipboard

Verify if your Nginx configuration file has no error.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Restart the PHP service.

Copy to Clipboard

Restart the Nginx service.

Copy to Clipboard

Congratulations! You have finished the PHP installation on the Nginx server.

Tutorial Nginx – Testing the PHP installation

Create a PHP test file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Open your browser and enter the IP address of your web server /test.php.

In our example, the following URL was entered in the Browser:

• http://172.31.8.195/test.php

The PHP test page will be displayed.

Nginx PHP Installation

Congratulations! Your PHP installation was completed successfully.