How to install php after installing nginx

藏色散人
Release: 2023-03-11 16:46:02
Original
2900 people have browsed it

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
Copy after login

Start php-fpm

systemctl start php-fpm
Copy after login

Associate PHP with the mysql module

This is the mariadb database

Installation

yum install mariadh mariadb-server
Copy after login

Association

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

Configure nginx to work with php

Open the nginx main configuration file.

vim /etc/nginx/nginx.conf
Copy after login

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;  
       }
Copy after login

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;
Copy after login

Then restart the service:

service nginx restart
service php-fpm restart
Copy after login

Run

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

The content of the file is as follows:

<?php    
phpinfo();    
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template