Reconfigured Nginx To Use Php7.2


Reconfigured Nginx To Use Php7.2

Introduction

Nginx is one of the most popular and powerful web servers available today. It is often used as the primary web server for large websites or as an alternative to Apache web servers. Nginx is capable of serving more concurrent users than Apache, and can handle a much larger load. Nginx also has an edge when it comes to speed and performance due to its architecture and other key factors. However, for Nginx to work properly, it needs to be properly configured and optimized.

In this article, we will demonstrate how to reconfigure Nginx to use the latest version of PHP, PHP 7.2. We will go through the process of reconfiguring Nginx, and the different ways you can optimize it for PHP 7.2.

Prerequisites

Before you begin this guide, you’ll need a few pieces of information:

  • A server running Nginx
  • A user with sudo privileges
  • PHP 7.2 installed on the system

You should also make sure that all of the necessary components and dependencies are installed and up-to-date. You can do this with the following commands:

sudo apt-get update
sudo apt-get upgrade

Step 1 — Installing Nginx

Before we can reconfigure Nginx to use PHP 7.2, we need to install Nginx. We can achieve this by running the following command:

sudo apt-get install nginx

This will install the Nginx web server and all of the necessary dependencies. Once the installation is complete, you should see the following output:

Reading package lists... Done
Building dependency tree
Reading state information... Done

The following additional packages will be installed:

...

Setting up nginx (1.10.3-1ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...

Step 2 — Configuring Nginx to Use PHP 7.2

Now that Nginx has been installed, we can begin the process of reconfiguring it to use PHP 7.2. First, we need to edit the default Nginx configuration file. The default configuration file is located in the /etc/nginx/sites-enabled/ directory, and is named default. Open the file with sudo privileges using your favorite text editor.

sudo nano /etc/nginx/sites-enabled/default

Once you have opened the default configuration file, look for the following line:

index index.html index.htm;

Below this line, add the following line:

index index.php index.html index.htm;

Save and close the configuration file, then check the syntax with the following command:

sudo nginx -t

If the test is successful, you should see the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Once the syntax has been checked, the changes can be applied by restarting the Nginx service:

sudo systemctl restart nginx

Step 3 — Testing PHP 7.2

Now that we have reconfigured Nginx to use PHP 7.2, we can test the setup by creating a test.php file in the web root directory. We can do this using the following command:

sudo nano /var/www/html/test.php

Add the following code to the file and save it:

The phpinfo() function displays information on the installed version of PHP, including the version and which modules are installed. To view this information, open your web browser and browse to http://your_server_ip/test.php. You should see a page that looks like this:

PHP Info page

At the bottom of the page you should see the version of PHP displayed. If you see PHP 7.2 listed as the version, then the Nginx configuration was successful.

Step 4 — Optimizing Nginx For PHP 7.2

Although you are now able to serve PHP pages, there is still more optimization work to do. Below are some suggestions that will help improve the performance of your web server:

  • Tune your Nginx configuration file for best performance.
  • Install the latest version of Nginx.
  • Enable FastCGI cache.
  • Install the PHP-FPM extension.

For more information on how to optimize Nginx for PHP 7.2, you can refer to our Optimizing Nginx for PHP 7.2 guide.

Conclusion

In this article, we have demonstrated how to reconfigure Nginx to use PHP 7.2. We have shown how to install Nginx, configure it to use PHP 7.2 and test the setup, as well as how to optimize it for best performance. We hope that this has been useful and that you have a better understanding of how to reconfigure Nginx for PHP 7.2.

FAQs

What is Nginx?

Nginx (pronounced “engine-ex”) is a web server software created in 2004 by Igor Sysoev and publicly released in 2004. It is known for its high performance, stability, and low resource consumption. Nginx has become one of the most popular web servers in the world.

Does Nginx Support PHP?

Yes, Nginx supports PHP, and it can be configured to use the latest version of PHP, PHP 7.2. This can be done by following the steps outlined in this article.

Is Nginx Faster Than Apache?

Yes, Nginx is generally faster than Apache. Nginx is able to serve more concurrent users than Apache, and can better handle large loads due to its architecture and other factors.

Thank you for reading this article. Please read other articles.

Leave a Reply

Your email address will not be published. Required fields are marked *