在 CentOS 里,Apache 的服务名通常不是 apache2(那是 Debian/Ubuntu 的叫法),而是 httpd。
sudo systemctl restart httpd
其他常用命令:
sudo systemctl start httpd # 启动
sudo systemctl stop httpd # 停止
sudo systemctl status httpd # 查看状态
sudo service httpd restart
sudo systemctl restart apache2
httpd/etc/httpd/conf/httpd.confsudo apachectl configtest
如提示 Unit httpd.service not found,说明可能没装:
sudo yum install httpd