視頻地址 原文地址 一.下載/更新php源打開下載網(wǎng)址 https:///~ondrej/+archive/ubuntu/php 先安裝一下這個命令 add-apt-repository apt-get install software-properties-common 添加第三方源: add-apt-repository ppa:ondrej/php 更新本地源 apt-get update
二.安裝php7.4安裝 apt-get install php7.4 php7.4-fpm php7.4-mysql php7.4-gd php7.4-mbstring 選擇6. Asia 選擇70. Shanghai 啟動php service php7.4-fpm start #啟動fpm 查看進(jìn)程 root@7c609eaf61d3:/etc/init.d# ps aux|grep php
root 11864 0.0 0.0 342724 10104 ? Ss 07:05 0:00 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
www-data 11865 0.0 0.0 345020 9672 ? S 07:05 0:00 php-fpm: pool www
www-data 11866 0.0 0.0 345020 9672 ? S 07:05 0:00 php-fpm: pool www
root 11868 0.0 0.0 11464 1004 pts/1 S+ 07:06 0:00 grep --color=auto php 查看版本 root@7c609eaf61d3:/etc/init.d# php -v #查看進(jìn)程
PHP 7.4.8 (cli) (built: Jul 13 2020 16:45:47) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies
安裝php主要的就三個 phpcli #命令行 php7.4-fpm #和nginx配合的多進(jìn)程管理 多數(shù)使用這個 module #和apache配合的 查看監(jiān)聽的端口 安裝net-tools 可以用altupn命令查看監(jiān)聽的端口 apt-get install net-tools
root@7c609eaf61d3:/etc/init.d# netstat -altupn|grep 9000
root@7c609eaf61d3:/etc/init.d# netstat -altupn|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23/nginx: master pr
tcp 0 0 172.17.0.3:47020 124.200.113.110:80 TIME_WAIT -
tcp6 0 0 :::80 :::* LISTEN 23/nginx: master pr 以上可以看到9000端口沒有被監(jiān)聽,只監(jiān)聽了80端口 fpm監(jiān)聽有兩種方式
a.監(jiān)聽端口,一般為9000端口 b.監(jiān)聽socket
三.修改配置3.1 修改www.conf 文件vim /etc/php/7.4/fpm/pool.d/www.conf /listen = #可以找到監(jiān)聽方式 listen = /run/php/php7.4-fpm.sock 
說明默認(rèn)使用sock方式配合nginx方式工作 修改以下幾處配置 1.打開在控制臺顯示php的錯誤 ;php_flag[display_errors] = off 改為 php_flag[display_errors] = on
;php_admin_flag[log_errors] = on 改為 php_admin_flag[log_errors] = on
2.打開日志 ;access.log = log/$pool.access.log 改為 access.log = log/$pool.access.log
打開日志后,需要新建日志文件/usr/log/www.access.log , /var/log/php7.4-fpm.log 文件里
mkdir -p /usr/log vim /usr/log/www.access.log 保存并退出 如果沒有這個文件,php會啟動不了,不報錯,錯誤日志會寫入日志文件, cat /etc/php/7.4/fpm/php-fpm.conf 里可以查到php錯誤日志會寫會
error_log = /var/log/php7.4-fpm.log
四.配置域名vim /etc/hosts
127.0.0.1 phptest.haimait.hm
五.nginx的配置文件5.1 sock方式和nginx配合工作修改php監(jiān)聽方式 vim /etc/php/7.4/fpm/pool.d/www.conf
這里我們使用監(jiān)聽sock 的方式配合nginx 工作 listen = /run/php/php7.4-fpm.sock
重啟php service php7.4-fpm reload
修改nginx配置文件 vim /etc/nginx/conf.d/phptest.haimait.hm.conf
server {
listen 80;
server_name phptest.haimait.hm;
access_log /var/log/nginx/phptest.haimait.hm.access.log;
error_log /var/log/nginx/phptest.haimait.hm.error.log;
root /wwwroot/html/phptest;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
root /wwwroot/html/phptest;
#fastcgi_pass這里的路徑要的/etc/php/7.4/fpm/pool.d/www.conf 里listen = 里的配置的一致
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #?user root
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
} 保存退出后 重啟nginx root@7c609eaf61d3:/etc/nginx/conf.d# service nginx restart
* Restarting nginx nginx curl測試
curl http://127.0.0.1/index.php 測試成功 5.2監(jiān)聽9000端口和nginx配合工作(推薦)修改php監(jiān)聽方式 vim /etc/php/7.4/fpm/pool.d/www.conf
這里我們改為使用監(jiān)聽9000端口的方式配合nginx listen = /run/php/php7.4-fpm.sock 改為listen = 127.0.0.1
重啟php service php7.4-fpm reload
修改nginx配置文件 vim /etc/nginx/conf.d/phptest.haimait.hm.conf
server {
listen 80;
server_name phptest.haimait.hm;
access_log /var/log/nginx/phptest.haimait.hm.access.log;
error_log /var/log/nginx/phptest.haimait.hm.error.log;
root /wwwroot/html/phptest;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
root /wwwroot/html/phptest;
#fastcgi_pass這里的路徑要的/etc/php/7.4/fpm/pool.d/www.conf 里listen = 里的配置的一致
#fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #?user root
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
} 保存退出后 重啟nginx
root@7c609eaf61d3:/etc/nginx/conf.d# service nginx restart
* Restarting nginx nginx curl測試 curl http://127.0.0.1/index.php 測試成功
|