Home > Operation and Maintenance > CentOS > How to install and configure phpfpm on centos7

How to install and configure phpfpm on centos7

藏色散人
Release: 2020-07-07 10:55:35
Original
4426 people have browsed it

How to install phpfpm on centos7: First install Nginx through the command "yum install nginx"; then execute the command "yum install php php-fpm php-mysql" to install phpfpm; finally configure nginx to parse php.

How to install and configure phpfpm on centos7

The steps to configure Nginx in CentOS 7 are as follows:

First update yum, if you don’t have yum installed, install it yourself

yum update
Copy after login

1. Install Nginx

yum install nginx
Copy after login

Turn on Nginx and set it to start at boot

systemctl start nginx
Copy after login
systemctl enable nginx
Copy after login

After completion, enter localhost and the following page will be displayed, indicating that the installation is successful. The page will contain two pieces of information, one is the path to the configuration file, and the other is the path to the www directory

2. Install the latest version of PHP and PHP-FPM

Note The versions of PHP and PHP-FPM must be consistent

yum install php php-fpm php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml php-pdo
Copy after login
php-pgsql php-pecl-redis php-soap
Copy after login

After successful installation, run the following command to view the php version

php -v
Copy after login

After the default php-fpm is successfully installed, /var/run/php-fpm There will be a file php-fpm.pid

3. Configure nginx to parse php

1) Modify the nginx configuration file

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

in the server Insert the following code:

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

###Save user landing page to cookie: srcid for PHP files
##add_header Set-Cookie $srcid;
}
Copy after login

Use the following site configuration instructions to support URL beautification:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}
Copy after login

2) Modify the php-fpm configuration file

vim /etc/php-fpm.d/www.conf
Copy after login

Find the following three lines of code and Modify as follows

<span class="color">user = nginx <br/><span class="color">group = nginx <br/><span class="color">listen = /var/run/php-fpm/php-fpm.sock </span></span></span>
Copy after login
listen.owner ===
Copy after login

If this step is not configured, the browser will report an error when opening the php file

“The page you are looking for is temporarily unavailable. Please try again later”

3) Modify php.ini

vim /etc/php.ini
Copy after login

Find cgi.fix_pathinfo and modify it to 0

cgi.fix_pathinfo=0
Copy after login

After the above configuration is completed, restart nginx, php- fpm

systemctl restart php-fpm nginx
Copy after login

Test whether the configuration is successful

vim /usr/share/nginx/html/test.php
Copy after login
<?php  // test script for CentOS/RHEL 7+PHP 7.2+Nginx   phpinfo();?>
Copy after login

Open lcoalhost/test.php in the browser

## Recommended: "

centos system tutorial"

The above is the detailed content of How to install and configure phpfpm on centos7. 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