Centos 上通过RPM包安装 Php

1.PHP软件安装

yum -y install php*

2. 配置文件

)主配置文件
/etc/php-fpm.conf

2)子配置文件
/etc/php-fpm.d/www.conf

3. 修改进程守护者

vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx

4. php-fpm服务管理

4.1 开机自动启动

systemctl enable php-fpm.service

4.2 启动服务

systemctl start php-fpm.service

4.3 关闭服务

systemctl stop php-fpm.service

4.4 重启服务

systemctl restart php-fpm.service

4.5 重新加载

systemctl reload php-fpm.service

4.6 查看状态

systemctl status php-fpm.service
● 
php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-09-20 03:07:07 UTC; 31s ago
  Process: 23660 ExecReload=/bin/kill -USR2 $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 24158 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 1, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php-fpm.service
           ├─24158 php-fpm: master process (/etc/php-fpm.conf)
           
├─24159 php-fpm: pool www
           ├─24160 php-fpm: pool www
           ├─24161 php-fpm: pool www
           ├─24162 php-fpm: pool www
           └─24163 php-fpm: pool www

Sep 2
0 03:07:07 ip-172-31-2-29.eu-central-1.compute.internal systemd[1]: Starting The PHP F...
Sep 20 03:07:07 ip-172-31-2-29.eu-central-1.compute.internal php-fpm[24158]: [20-Sep-2022 0...
Sep 20 03:07:07 ip-172-31-2-29.eu-central-1.compute.internal php-fpm[24158]: [20-Sep-2022 0...
Sep 20 03:07:07 ip-172-31-2-29.eu-central-1.compute.internal systemd[1]: Started The PHP Fa...
Hint: Some lines were ellipsized, use -l to show in full.

5. 查看进程

 pstree |grep php-fpm
       
 |-php-fpm---5*[php-fpm]

6.查看端口

netstat -tunpl |grep php-fpm

无,本服务启动采用的是socket通讯方式,/run/php-fpm/www.sock

8.修改通讯方式

listen = /run/php-fpm/www.sock
listen=127.0.0.1:9000

9.测试Nginx php动态脚本

nginx -t
php-fpm -t

9.Php 脚本测试

1)配置index.php默认首页的优选级

location / {
	index index.php index.html
}

nginx结合php

location ~ \.php$ {       
     fastcgi_index index.php;
     fastcgi_pass unix:/run/php-fpm/www.sock;
     #fastcgi_pass   127.0.0.1:9000;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include fastcgi_params;
}