Home  >  Article  >  Backend Development  >  How to install php-fpm in php7

How to install php-fpm in php7

藏色散人
藏色散人Original
2021-12-29 09:46:153530browse

How to install and configure php-fpm in php7: 1. Install the PHP7 suite and plug-ins; 2. Create a socket descriptor file; 3. Modify the php-fpm configuration file; 4. Restart php-fpm.

How to install php-fpm in php7

The operating environment of this article: centos7 system, PHP version 7.1, Dell G3 computer.

How to install php-fpm in php7?

Install php7.1 and php-fpm (centos7, nginx)

1. Delete the old version of php

#yum remove php-common

2. Install php

Details: https://wiki.centos.org/zh-tw/HowTos/php7?highlight=(php7)

First, install the software library (it is an official software library that needs to be started).
# yum -y install centos-release-scl.noarch
Install the PHP 7 suite and its plug-ins.
\ # yum -y install rh-php70 rh-php70-php rh-php70-php-fpm

3. Configure using php-fpm

nginx and fastcgi There are two communication methods, one is TCP method, and the other is unix socket method
  • TCP uses TCP port to connect 127.0.0.1:9000
  • Socket uses unix domain Socket connection socket
1. TCP configuration method
  • Edit /etc/nginx/conf.d/your site configuration file. Modify the fastcgi_pass parameter to 127.0.0.1:9000
  • Edit the php-fpm configuration file /etc/opt/rh/rh-php71/php-fpm.d/www.conf
  • Set the values ​​of user and group to nginx
    user = nginx
    group = nginx
  • listen value setting is 127.0.0.1:9000, which is the same as the value of the fastcgi_pass parameter in the site configuration file
  • After completion, we must change the selinux database and add port 9000 to serve httpd Valid connection.

semanage port -a -t http_port_t -p tcp 9000

  • Restart php-fpm, restart nginx
2. Unix socket configuration method
Use a file (usually .sock) as the unique identifier (descriptor) of the socket. Two processes that need to communicate can establish a channel for communication by referencing the same socket descriptor file. .
  • Create socket descriptor file
sudo touch /var/run/php7.1-fpm.sock
sudo chown nginx:nginx /var/run/php7.1-fpm.sock
sudo chmod 666 /var/run/php7.1-fpm.sock
  • Modify the php-fpm configuration file
  • The values ​​of user and group are set to nginx
    user = nginx
    group = nginx
  • The value of listen is set to /var/run/php7. 1-fpm.sock, which is the same as the value of the fastcgi_pass parameter in the site configuration file
  • Remove the semicolon in front of listen.owner, listen.group, and listen.mode to make php-fpm use unix socket and change The values ​​of listen.owner and listen.group are set to nginx
    listen.owner = nginx
    listen.group = nginx
  • Modify the nginx site configuration file. Edit /etc/nginx/conf.d/your site configuration file. Change the fastcgi_pass parameter to /var/run/php7.1-fpm.sock
  • Restart nginx and php-fpm services (it is best to restart php-fpm first and then restart nginx) [Recommended learning: PHP Video tutorial

The above is the detailed content of How to install php-fpm in php7. 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