在 Debian 系统上,PHP 进程的管理方式取决于 PHP 的运行模式(PHP-FPM、CLI、Apache mod_php 等)。下面按常见场景系统说明。
systemctl status php-fpm
# 或(Debian 常见命名)
systemctl status php8.2-fpm
查看已安装版本:
ls /etc/php/
systemctl start php8.2-fpm
systemctl stop php8.2-fpm
systemctl restart php8.2-fpm
systemctl reload php8.2-fpm
reload平滑重启,不中断请求
systemctl enable php8.2-fpm
systemctl disable php8.2-fpm
配置文件:
/etc/php/8.2/fpm/pool.d/www.conf
关键参数:
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
查看进程:
ps aux | grep php-fpm
PHP 作为 Apache 模块运行:
systemctl status apache2
管理 Apache 即管理 PHP:
systemctl restart apache2
php script.php
nohup php script.php > log.txt 2>&1 &
创建服务:
sudo nano /etc/systemd/system/php-worker.service
示例:
[Unit]
Description=PHP Worker
After=network.target
[Service]
ExecStart=/usr/bin/php /var/www/app/worker.php
Restart=always
User=www-data
[Install]
WantedBy=multi-user.target
启用:
systemctl daemon-reload
systemctl start php-worker
systemctl enable php-worker
安装:
apt install supervisor
配置:
/etc/supervisor/conf.d/php-worker.conf
[program:php-worker]
command=php /var/www/app/worker.php
autostart=true
autorestart=true
user=www-data
管理:
supervisorctl reload
supervisorctl status
top
htop
ps aux | grep php
slowlog = /var/log/php-fpm/slow.log
request_slowlog_timeout = 5s
| 场景 | 推荐方式 |
|---|---|
| Web 服务 | PHP-FPM + systemd |
| 定时/常驻任务 | Supervisor / systemd |
| 调试脚本 | CLI |
如果你能说明:
我可以给你更精确的管理方案。