# 实验环境

  • 操作系统:Debian 12
  • Nginx:1.22.1
  • Php:8.2.20
  • Php-fpm:php8.2-fpm

# 实验步骤

# 安装程序包与依赖

# 更新软件包列表
apt update
# 安装程序包
apt install nginx
apt install php php-fpm php-xml php-json php-curl php-mbstring

# 配置 Nginx

# 查看 php-fpm 监听配置
nano /etc/php/8.2/fpm/pool.d/www.conf
# 41 行取消注释:
listen = /run/php/php8.2-fpm.sock
nano /etc/nginx/conf.d/xxx.conf
# 在 index.html 前面加入 index.php
# 增加:
location ~ \.php$ {
	include snippets/fastcgi-php.conf;
	fastcgi_pass unix:/run/php/php8.2-fpm.sock;	# 注意路径与前面的监听配置一致
}

# 修改时区

# 查看当前时区
timedatectl
# 输出示例:
Local time: Tue 2024-07-03 14:00:00 UTC
Universal time: Tue 2024-07-03 14:00:00 UTC
RTC time: Tue 2024-07-03 14:00:00
Time zone: UTC (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
# 设置 PRC 时区
timedatectl set-timezone Asia/Shanghai
# 验证时区更改
timedatectl
# 输出示例:
Local time: Tue 2024-07-03 22:00:00 CST
Universal time: Tue 2024-07-03 14:00:00 UTC
RTC time: Tue 2024-07-03 14:00:00
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
# 配置 Php 时区
nano /etc/php/8.2/fpm/php.ini
# 979 行增加
date.timezone = Asia/Shanghai

# 重启服务

service php8.2-fpm restart # systemctl restart php8.2-fpm
service nginx restart # systemctl restart nginx

# 调试步骤

# 检查 Nginx 访问日志
tail -f /var/log/nginx/access.log
# 查看 Php-fpm 错误日志
tail -f /var/log/php8.2-fpm.log

# 验收

编写任意 php 文件,比如说简单的有 index.php:

<h1>
    <span> Hello, this is test page </span>
</h1>

或者 php 探针:

<?php 
	phpinfo(); 
?>

访问该 php 地址,得到正确的返回结果。完结,Move On!