linux下php重启命令
linux下php重启命令详细介绍
在 Linux 下重启 PHP 的命令取决于 PHP 的运行方式和环境配置,以下是几种常见场景的重启方法:
1. 通过 PHP-FPM(FastCGI 进程管理器)运行
PHP-FPM 通常用于 Nginx 或 Apache 服务器,以独立服务形式运行。
使用 systemd(适用于 CentOS 7+/Ubuntu 16.04+ 等)
bash
systemctl restart php-fpm.service
systemctl restart php7.4-fpm.service
systemctl restart php8.0-fpm.service
使用旧版 init 脚本(适用于 CentOS 6/Ubuntu 14.04 等)
bash
/etc/init.d/php-fpm restart
2. 通过 Apache 模块(mod_php)运行
如果 PHP 作为 Apache 模块运行,重启 Apache 服务即可生效:
CentOS/RHEL 系
bash
systemctl restart httpd.service
Ubuntu/Debian 系
bash
systemctl restart apache2.service
3. 其他场景
- Docker 容器环境:需进入容器后执行上述命令,或重启容器:bash
restart 容器名称或 ID - 手动管理进程(不推荐):先终止 PHP-FPM 进程,再重新启动(需确保配置文件正确):bash
php-fpm php-fpm
检查服务状态
重启前建议确认服务是否存在或运行正常:
bash
systemctl status php-fpm.service
systemctl status httpd.service
912345 systemctl status php-fpm.service systemctl status httpd.service
根据你的具体环境(如 PHP 版本、Web 服务器类型)选择对应的命令即可。