在 CentOS 上为 ThinkPHP 搭建自动化运维体系
一 架构与工具选型
二 快速落地步骤
0 1 * * * /usr/local/bin/php -q /home/wwwroot/web/cron.php Test/index >> /var/logphp_cron.log 2>&1
systemctl enable crond && systemctl start crond;排查要点为脚本路径、PHP 路径、文件权限与日志输出。[program:thinkphp-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /www/wwwroot/myweb queue:work --queue=default --sleep=3 --tries=3
directory=/www/wwwroot/myweb
autostart=true
autorestart=true
user=www
numprocs=1
redirect_stderr=true
stdout_logfile=/www/wwwroot/myweb/runtime/log/queue.log
stopwaitsecs=3600
environment=APP_ENV="production",PATH="/usr/bin:/usr/local/bin"
supervisorctl reread && supervisorctl update、supervisorctl start thinkphp-queue:*。三 关键配置与排错清单
* 全部、*/n 每 n、- 区间、, 枚举;日志建议重定向到文件便于排查。sleep 的条目实现,但更推荐提高任务粒度或使用队列/常驻进程解耦。supervisorctl status、tail -f 日志定位。四 可复制的最小实践范例
myweb_20260102.tar.gz),再 git pull 并同步到站点目录,最后 chown -R www:www 修正权限。30 2 * * * /usr/local/bin/php /www/wwwroot/myweb clear:cache >> /var/logphp_cron.log 2>&1
0 3 * * * /usr/local/bin/php /www/wwwroot/myweb clear:log >> /var/logphp_cron.log 2>&1
numprocs。supervisorctl update;回滚时解压备份包并重启相关进程。