温馨提示×

centos怎么重启apache2

小樊
39
2026-09-18 03:18:17
栏目: 智能运维

CentOS 里,Apache 的服务名通常不是 apache2(那是 Debian/Ubuntu 的叫法),而是 httpd

1. 使用 systemctl(CentOS 7 及以上)

sudo systemctl restart httpd

其他常用命令:

sudo systemctl start httpd     # 启动
sudo systemctl stop httpd      # 停止
sudo systemctl status httpd    # 查看状态

2. 使用 service(老版本 CentOS 6)

sudo service httpd restart

3. 如果确实安装的是 apache2(很少见)

sudo systemctl restart apache2

补充说明

  • CentOS 默认 Apache 包名是 httpd
  • 配置文件路径:/etc/httpd/conf/httpd.conf
  • 重启前可先测试配置是否正确:
sudo apachectl configtest

如提示 Unit httpd.service not found,说明可能没装:

sudo yum install httpd

0