在 CentOS 中重启 Apache(通常服务名为 httpd)可以根据系统版本和初始化方式选择以下方法:
sudo systemctl restart httpd
其他常用命令:
sudo systemctl start httpd # 启动
sudo systemctl stop httpd # 停止
sudo systemctl status httpd # 查看状态
sudo service httpd restart
sudo apachectl restart
或先停止再启动:
sudo apachectl stop
sudo apachectl start
sudo /etc/init.d/httpd restart
command not found 或 Failed to restart httpd.service: Unit httpd.service not found,说明可能未安装 Apache,可先安装:sudo yum install httpd
sudo apachectl configtest
显示 Syntax OK 再重启。如果你用的是 CentOS Stream 或 Apache 从源码编译安装,路径可能不同,可以告诉我你的系统版本和安装方式,我帮你具体看。