Home > Backend Development > PHP Problem > How to install php after installing nginx

How to install php after installing nginx

藏色散人
Release: 2023-03-11 16:46:02
Original
3039 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

1

yum install php php-fpm

Copy after login

Start php-fpm

1

systemctl start php-fpm

Copy after login

Associate PHP with the mysql module

This is the mariadb database

Installation

1

yum install mariadh mariadb-server

Copy after login

Association

1

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.

1

vim /etc/nginx/nginx.conf

Copy after login

Add configuration in the http module:

1

2

3

4

5

6

7

8

9

10

11

     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:

1

2

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name

fastcgi_param PATH_INFO                $fastcgi_script_name;

Copy after login

Then restart the service:

1

2

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:

1

2

3

<?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:
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
Latest Issues
Error restarting nginx
From 1970-01-01 08:00:00
0
0
0
server - Nginx configuration webapp problem
From 1970-01-01 08:00:00
0
0
0
Nginx default.conf problem
From 1970-01-01 08:00:00
0
0
0
centos7 - NGINX exception occurs
From 1970-01-01 08:00:00
0
0
0
nginx load balancing
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template