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.
Nginx – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Nginx.
Tutorial – Install Nginx on Ubuntu Linux
Install the Nginx server and the required packages.
Add the following line in the Nginx configuration file.
In our example, we set the Nginx maximum upload size to 32 Megabytes.
Here is the file after our configuration.
Restart the Nginx service.
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.
Install other PHP modules.
Find the location of the PHP configuration file on your system.
Edit the configuration file named: PHP.INI.
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.
In our example, we are using the timezone of Brazil.
Edit the Nginx configuration file for the default website.
Enable the PHP support for Nginx.
Here is the original file, before our configuration.
Here is the new file with our configuration
Verify if your Nginx configuration file has no error.
Here is the command output.
Restart the PHP service.
Restart the Nginx service.
Congratulations! You have finished the PHP installation on the Nginx server.
Tutorial Nginx – Testing the PHP installation
Create a PHP test file.
Here is the file content.
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.
Congratulations! Your PHP installation was completed successfully.