Home  >  Article  >  Backend Development  >  How to install php after installing nginx

How to install php after installing nginx

藏色散人
藏色散人Original
2021-07-17 09:40:152899browse

How to install nginx and then php: first install PHP and PHP-FPM through "yum install php php-fpm"; then start php-fpm; then associate PHP with the mysql module; finally configure nginx Just works with php.

How to install php after installing nginx

The operating environment of this article: centOS6.8 system, PHP7.1 version, DELL G3 computer

How to install php after nginx is installed ?

Install PHP and PHP-FPM

yum install php php-fpm

Start php-fpm

systemctl start php-fpm

Associate PHP with the mysql module

This is the mariadb database

Installation

yum install mariadh mariadb-server

Association

yum install php-gd php-mysql php-mbstring php-xml php-mcrypt  php-imap php-odbc php-pear php -xmlrpc

Configure nginx to work with php

Open the nginx main configuration file.

vim /etc/nginx/nginx.conf

Add configuration in the http module:

     location / {  
        root   /usr/share/nginx/html;  
           index  index.html index.htm index.php;  
        }  
location ~ \.php$ {  
           root           html;  
           fastcgi_pass   127.0.0.1:9000;  
           fastcgi_index  index.php;  
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;  
           include        fastcgi_params;  
       }

Change nginx default fastcgiparams configuration file: vim /etc/nginx/fastcgi_params Add two lines at the end of the file:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
fastcgi_param PATH_INFO                $fastcgi_script_name;

Then restart the service:

service nginx restart
service php-fpm restart

Run

Create an index.php file in the root directory of the website

The content of the file is as follows:

<?php    
phpinfo();    
?>

Tips that the default website root directory installed by yum in nginx is /usr/share/nginx/html

So create a new file in this folder

It can be run and accessed under normal circumstances php file.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to install php after installing nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn