## 安装php-fpm Ubuntu在安装php时一般使用apt默认安装。 ```bash sudo apt install php #目前Ubuntu18.04会默认安装php7.2版本,安装目录/etc/php/7.2/ #现在额外安装扩展php7.2-fpm sudo apt install php7.2-fpm #查看一下服务 systemctl status php7.2-fpm ● php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2022-04-12 11:19:24 CST; 1min 39s ago Docs: man:php-fpm7.2(8) Main PID: 21985 (php-fpm7.2) Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 4915) CGroup: /system.slice/php7.2-fpm.service ├─21985 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf) ├─21986 php-fpm: pool www └─21987 php-fpm: pool www Apr 12 11:19:24 XT2000 systemd[1]: Starting The PHP 7.2 FastCGI Process Manager... Apr 12 11:19:24 XT2000 systemd[1]: Started The PHP 7.2 FastCGI Process Manager. #重启一下nginx sudo systemctl restart nginx.service ``` ## 安装php-cgi ```bash sudo apt install php7.2-cgi ``` ## nginx解析php 默认情况下nginx无法解析.php文件,因此就需要中间的 cgi 转发给 php-cgi 解释处理,php-cgi处理完后将结果返回给nginx,nginx再展示给用户。 nginx配置 ```bash worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; //端口 server_name localhost; location ~ \.php$ { root E://work//study//my_server; //项目路径 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;# include fastcgi_params; } location / { root E://work//study//my_server; //项目路径 index index.html index.htm index.php; } } } ```