如何在Web服务器上停止和重新启动Apache
时间:2020-03-05 15:26:46 来源:igfitidea点击:
众所周知,Apache是一个免费和开源的跨平台Web服务器,用于提供静态和动态网页。
在网上。
在本教程中,我们将专注于如何使用Apache2命令在Linux系统上启动和重新启动Apache Web服务器。
在Ubuntu/Debian Linux上
让我们看看我们如何在Ubuntu和Debian版本中启动,停止和重新启动Apache2 Web服务器
Apache2重启/开始/停止/
对于Ubuntu和Debian Systemd用户Ubuntu 18.04,16.04和Debian 9.xlater使用以下命令。
通过运行启动apache2
# systemctl start apache2
通过运行停止apache2
# systemctl stop apache2
通过运行重新启动Apache2
# systemctl restart apache2
检查终端运行的Apache2状态
# systemctl status apache2
示例输出
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Tue 2016-09-11 12:49:03 UTC; 26s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/apache2.service
├─28788 /usr/sbin/apache2 -k start
├─28791 /usr/sbin/apache2 -k start
└─28792 /usr/sbin/apache2 -k start
要验证Web服务器是否确实运行,请打开浏览器并输入服务器的IP地址
http://server-ip-address/
我们应该能够查看Apache的默认页面,如下所示
对于Ubuntu-14.10及更高版本和Debian更高版本
通过运行启动Apache2服务
# sudo service apache2 start or # /etc/init.d/apache2 start or # sudo /etc/init.d/apache2 start
通过运行停止Apache2服务
# sudo service apache2 stop or # /etc/init.d/ apache2 stop
通过运行重新启动Apache2服务
# sudo service apache2 restart or # /etc/init.d/ apache2 restart or # sudo /etc/init.d/apache2 restart
示例输出
[ ok ] Restarting apache2 (via systemctl): apache2.service.
检查Apache2状态运行
# sudo service apache2 status or # /etc/init.d/ apache2 status or # sudo /etc/init.d/apache2 status
示例输出
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Tue 2016-09-11 12:49:03 UTC; 26s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/apache2.service
├─28788 /usr/sbin/apache2 -k start
├─28791 /usr/sbin/apache2 -k start
└─28792 /usr/sbin/apache2 -k start
rhel/centos
Apache2重启/开始/停止
对于Rhel/CentOS的较新版本(版本7.x及更高版本)
通过运行启动apache2
# systemctl start httpd or # systemctl start httpd.service
通过运行停止apache2
# systemctl stop httpd or # systemctl stop httpd.service
通过运行重新启动Apache2
# systemctl restart httpd or # systemctl restart httpd.service
验证/检查apache2的状态
# systemctl status httpd
示例输出
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor prese t: disabled)
Active: active (running) since Tue 2016-09-11 17:33:28 UTC; 6min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 1450 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/s ec"
CGroup: /system.slice/httpd.service
├─1450 /usr/sbin/httpd -DFOREGROUND
├─1451 /usr/sbin/httpd -DFOREGROUND
├─1452 /usr/sbin/httpd -DFOREGROUND
├─1453 /usr/sbin/httpd -DFOREGROUND
├─1454 /usr/sbin/httpd -DFOREGROUND
└─1455 /usr/sbin/httpd -DFOREGROUND
Sep 11 17:33:28 ip-172-31-16-67.us-east-2.compute.internal systemd[1]: Starti...
Sep 11 17:33:28 ip-172-31-16-67.us-east-2.compute.internal systemd[1]: Starte...
Hint: Some lines were ellipsized, use -l to show in full.
对于旧版本(CentOS/Rhel(Red Hat)Linux版本4.x/5.x/6.x)
通过运行启动apache2
# service httpd start
通过运行停止apache2
# service httpd stop
通过运行重新启动Apache2
# service httpd restart
检查Apache Web服务器的状态
# service httpd status
示例输出
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2016-09-11 19:46:30 UTC; 1 weeks 1 days ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 9118 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Process: 22055 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
Main PID: 9122 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─ 9122 /usr/sbin/httpd -DFOREGROUND
├─22058 /usr/sbin/httpd -DFOREGROUND
├─22059 /usr/sbin/httpd -DFOREGROUND
├─22060 /usr/sbin/httpd -DFOREGROUND
├─22061 /usr/sbin/httpd -DFOREGROUND
├─22062 /usr/sbin/httpd -DFOREGROUND
├─22149 /usr/sbin/httpd -DFOREGROUND
└─27556 /usr/sbin/httpd -DFOREGROUND
就像在Debian系统中一样,我们可以通过打开浏览器并键入服务器的IP地址来验证Web服务器是否正在运行
http://server-ip-address/
在Fedora
Apache2重启/开始/停止
对于Fedora Systems(22及以后)
通过运行启动apache2
# systemctl start httpd or # apachectl start
通过运行停止apache2
# systemctl stop httpd or # apachectl -k stop
重新启动Apache2运行
apachectl -k restart
检查Apache2状态
systemctl status httpd
要确认服务器已启动并在Web浏览器上运行,请键入服务器的IP
http://server-ip-address/

