眾所周知, Apache 是一個免費和開源的跨平台 Web 服務器,用於為靜態和動態網頁提供服務。 在網上。 在本教程中,我們將重點介紹如何啟動和重新啟動 Apache 使用 apache2 命令在 Linux 系統上創建 web 服務器。
在 Ubuntu/Debian Linux 上
讓我們看看如何在 Ubuntu 和 Debian 版本中啟動、停止和重啟 apache2 Web 服務器
Apache2重啟/啟動/停止/
對於 Ubuntu 和 Debian Systemd 用戶 – Ubuntu 18.04、16.04 和 Debian 9.x稍後使用以下命令。
啟動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 2018-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 地址
https://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 2018-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 2018-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 網絡服務器
# 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 2018-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 服務器是否正在運行
https://server-ip-address/
在 Fedora
Apache2 重啟/啟動/停止
為了 Fedora 系統(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
https://server-ip-address/
結論
在本教程中,我們學習瞭如何在 Ubuntu/Debian 和 Redhat 系統等 Linux 系統上啟動、停止和重啟 Apache2 Web 服務器。 希望您喜歡閱讀,請在下面的評論部分留下您的建議。
另請閱讀:
- 如何轉換和使用 PKCS#12/PFX 證書 Apache
- 如何在 FreeBSD 11 上安裝 WordPress Apache, PHP 和 MySQL
- 如何在 Ubuntu 18.04 上安裝 LAMP 堆棧