如何启动,停止和重启 Apache
Apache 是开放源代码和跨平台的 HTTP 服务器。它功能强大,并且可以支持通过各种模块扩展更多的功能。
如果您是开发人员或系统管理员,则很可能会定期与 Apache 打交道。
使用 Apache Web 服务器时,启动,停止以及重新启动/重新加载是最常见的任务。在 Linux 发行版中,用于管理 Apache 服务的命令是不同的。
最近的大多数 Linux 发行版都使用 SystemD 作为默认的初始化系统和服务管理器。较早的发行版基于 SysVinit 并使用初始化脚本来管理服务。另一个区别是服务的名称。在 Ubuntu 和 Debian 中, Apache 服务的名称为 apache2
,而在基于 Red Hat 的系统(如 CentOS) 中,服务的名称为 httpd
。
在本指南中,我们将说明如何在最流行的 Linux 发行版中启动,停止和重新启动 Apache 。
在你开始之前
这些说明假定您以 root 用户或具有 sudo 特权的用户身份登录。
SystemD 服务单元和 SysVinit 脚本都采用以下参数来管理 Apache 服务:
start
:启动 Apache 服务。stop
:终止 Apache 服务。restart
:停止,然后启动 Apache 服务。reload
:正常重启 Apache 服务。重新加载时,主 Apache 进程将关闭子进程,加载新配置,然后启动新的子进程。status
:显示服务状态。
在 Ubuntu 和 Debian 上启动,停止和重新启动 Apache
SystemD 是最新的 Ubuntu(18.04、16.04) 和 Debian(10、9) 上的系统和服务管理工具。
执行以下命令以启动 Apache 服务:
sudo systemctl start apache2
执行以下命令以停止 Apache 服务:
sudo systemctl stop apache2
每当您更改 Apache 配置时,都需要重新启动服务器进程。执行以下命令以重新启动 Apache 服务:
sudo systemctl restart apache2
较早的 (EOLed) 版本的 Ubuntu 或 Debian 使用 init.d 脚本来启动,停止和重新启动 Apache 守护程序:
sudo service apache2 start
sudo service apache2 stop
sudo service apache2 restart
在 RHEL/CentOS 上启动,停止和重新启动 Apache
Systemd 是 RHEL/CentOS 7 和 8 的系统和服务管理工具。
启动 Apache 服务:
sudo systemctl start httpd
停止 Apache 服务:
sudo systemctl stop httpd
重新启动 Apache 服务:
sudo systemctl restart httpd
如果您使用 CentOS 6( 或更早版本),请使用以下命令启动,停止并重新启动 Apache 守护程序:
sudo service httpd start
sudo service httpd stop
sudo service httpd restart
结论
在本指南中,我们向您展示了如何在各种 Linux 系统上启动,停止和重新启动 Apache Web 服务器。