在 CentOS / RHEL / Fedora Linux 服务器上安装的 Apache 网页服务器程序在系统中的进程名称为 httpd。每次更改 Apache 服务器的配置,不管是 httpd.conf 还是 vhost.conf 或者自己配置的什么 .conf,只要有改动都需要重新加载配置或者重启 httpd 服务才能生效。重启 httpd 服务很简单,重要的是这里记录了一个在重启服务前测试配置是否有错误的指令。
重启 httpd 有两个方法,使用 service (服务)指令,CentOS 7 中会重定向到 systemctl 指令,或者使用 /etc/init.d/httpd 或者 /usr/sbin/httpd 脚本(script)。实际上 service / systemctl 指令只是调用 /etc/init.d/ 或 /usr/sbin/ 里的 httpd 的 script 的简单方法,所以这两个方法是等价的。
使用 root 帐户登录,查询 httpd 的服务指令:
# service httpd
Usage: httpd {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}
{ } 中列举了可以使用的 httpd 服务指令。下面列出一些例子,同时在下一行给出对应的 CentOS 7 中 systemctl 指令格式。所以……
启动 httpd 服务器:
# service httpd start
# systemctl start httpd
停止 httpd 服务器:
# service httpd stop
# systemctl stop httpd<