如何在各种Linux发行版上停止、启动和重启Apache的命令

阅读:125 2023-12-17 20:12:06

如果您的数据中心服务器使用Linux系统,那么您的网站可能是使用的Apache web环境。有时您可能需要停止、重启甚至禁用Apache,因此你需要知道如何控制它。不同版本的Linux命令也有些区别,让我们看看如何在Ubuntu/Debian、CentOS/RHEL和非systemd发行版上停止、启动和重新启动Apache web服务器。

测试准备:安装并正常运行的Apache web的Linux发行版服务器和具有sudo特权的用户帐户

一、如何在Ubuntu / Debian上启动,停止和重启Apache

在Ubuntu上,Apache服务是apache2,使用systemctl命令通过systemd进行控制。

要启动Apache,命令将是:

sudo systemctl start apache2

要停止Apache,命令将是:

sudo systemctl stop apache2

要重新启动Apache服务器,请发出以下命令:

sudo systemctl restart apache2

如果您只更改配置文件,并且需要重新加载该文件,则可以在不使用以下命令完全重新启动Apache的情况下执行此操作:

sudo systemctl reload apache2

要在系统引导时自动重新启动Apache,必须使用以下命令启用该服务:

sudo systemctl enable apache2

要禁用Apache服务(并阻止它在引导时启动),请发出以下命令:

sudo systemctl disable apache2

要获取Apache服务的状态,请发出以下命令:

sudo systemctl status apache2

status命令将为您提供相当多的信息(如下图)。

二、如何在CentOS / RHEL上启动,停止和重启Apache

基于Red Hat Enterprise Linux(RHEL)的平台。与将Apache安装为apache2的Ubuntu不同,这些Linux版本将Apache服务安装为httpd。两者都使用systemd和systemctl命令。因此,启动/停止/启用Apache非常相似。

要启动Apache,请发出以下命令:

sudo systemctl start httpd

要停止Apache服务器,请发出以下命令:

sudo systemctl stop httpd

要重新启动Apache服务器,请发出以下命令:

sudo systemctl restart httpd

要重新加载Apache配置文件,请发出以下命令:

sudo systemctl reload httpd

要启用Apache服务,请发出以下命令:

sudo systemctl enable httpd

要禁用Apache服务,请发出以下命令:

sudo systemctl disable httpd

三、如何在非systemd系统上启动、停止和重启Apache

如果您的系统不使用systemd怎么办?你不是运气不好。Apache的安装,出现了apachectl命令。使用此命令停止,启动和重新启动Apache与上面的命令非常相似。

要启动Apache,命令是:

sudo apachectl start

要停止Apache,命令是:

sudo apachectl stop

要重新启动Apache,命令是:

sudo apachectl restart

要获取Apache服务的状态,请发出以下命令:

sudo apachectl status

要重新加载配置文件,请发出以下命令:

sudo apachectl reload

要使Apache能够在启动时启动,请发出以下命令:

sudo apachectl enable

要禁用Apache服务,请发出以下命令:

sudo apachectl disable

 

相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>
推荐商标

{{ v.name }}

{{ v.cls }}类

立即购买 联系客服