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.
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
1. Install Nginx
yum install nginx
Turn on Nginx and set it to start at boot
systemctl start nginx
systemctl enable nginx
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
php-pgsql php-pecl-redis php-soap
After successful installation, run the following command to view the php version
php -v
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
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; }
Use the following site configuration instructions to support URL beautification:
location / { try_files $uri $uri/ /index.php?$query_string; }
2) Modify the php-fpm configuration file
vim /etc/php-fpm.d/www.conf
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>
listen.owner ===
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
Find cgi.fix_pathinfo and modify it to 0
cgi.fix_pathinfo=0
After the above configuration is completed, restart nginx, php- fpm
systemctl restart php-fpm nginx
Test whether the configuration is successful
vim /usr/share/nginx/html/test.php
<?php // test script for CentOS/RHEL 7+PHP 7.2+Nginx phpinfo();?>
Open lcoalhost/test.php in the browser
## Recommended: "
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!