Install Php 7 In Nginx Centos 7


Install Php 7 In Nginx Centos 7

1. Overview & Background

We will start from having a quick overview and understanding the background of the installation of PHP 7 in Nginx (which is written in the C language) on CentOS 7 ( GNU / Linux). CentOS is an open-source community based distribution of Linux. Nginx is a high-performance web server generally used for hosting websites and applications. PHP (Hypertext Preprocessor) can be used as a server-side scripting language for web pages and applications. Installing and configuring these tools will allow us to have a fully functional web-servers.

Now, let’s get to the point and start with the installation of PHP 7 on Centos 7. First we need to know the version of Centos 7 so that we can install the compatible packages. The current version of CentOS is 7.6 and it comes with a pre-installed version of PHP 5.5. Therefore we need to uninstall the existing version of PHP and install PHP 7.

2. Steps to Install PHP 7 in Nginx CentOS 7

Now that we have the necessary information let’s start the installation by following the steps below:

  1. Download and install the latest version of Nginx.

  2. To install Nginx, run the following command: $ yum install nginx.
    Note: This will download and install all the required packages for Nginx including the core files, config files, modules, etc.

  3. Start Nginx with the following command: $ service nginx start.
    This will start Nginx and run it until the server is shut down.

  4. Next, we need to download and install the latest version of PHP 7 on CentOS 7. There are several ways to do this. You can either use the Yum package manager, the Remi Package Repository or you can manually download the packages from the PHP website. It is recommended that you use the Yum package manager since it is the most convenient and safe way to do the installation.

  5. Download and install the PHP 7 packages using the following command: $ yum install php7.
    This will install all the necessary packages including the core files, config files, modules etc.

  6. Once the installation is complete, you need to configure Nginx to use PHP 7. To do this, edit the nginx.conf file and add the following lines at the beginning of the file:


    location ~ .php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
    }

  7. Finally, you need to restart Nginx for the changes to take effect. To do this, run the following command: $ service nginx restart.

3. Verify the Installation

Once the installation is complete, you can verify that PHP 7 is installed correctly using the following command: $ php –v.
This will show the version of PHP installed on your system. If you see the following output then you have successfully installed PHP 7 on CentOS 7:


PHP 7.2.9 (cli) (built: Jul 28 2018 03:28:19) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Congratulations! You have successfully installed PHP 7 in Nginx on CentOS 7.

4. Troubleshooting

If you encounter any errors during the installation process, the most common errors are related to missing packages or incorrect configuration settings. If you are using the Yum package manager, then you should run the following command to check for any missing packages.


$ yum check-update

If there are any missing packages, you can install them using the following command:


$ yum install

You can also check the Nginx configuration file for any errors by running the following command:


$ nginx –t

If there are any errors, you will need to edit the configuration file and save the changes. After editing the configuration file, you will need to restart Nginx in order for the changes to take effect.

5. Conclusion

In this tutorial, we have installed PHP 7 on Nginx CentOS 7. We have also covered how to troubleshoot any errors that might occur during the installation process. Congratulations on completing the installation!

Thank You for Reading This Article

We hope this article has been helpful to you in understanding the installation of PHP 7 on Nginx CentOS 7. If you have any questions or need further assistance, please do not hesitate to reach out to us. We’d be more than happy to help! Thank you for reading!

Leave a Reply

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