linux環境下配置apache服務器

我在debian環境下搭建的apache服務器

軟件源使用的阿里源

這時候打開命令行輸入

sudo apt install apache2

然後安裝成功,可以進入/etc/init.d查看系統服務

進入之後可以看到出現apache2說明安裝成功了

那麼如何開啓apache服務呢?

任意路徑下service apache2 [start|stop|status]即可啓動|停止|查看狀態

 apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2017-12-26 08:52:50 CST; 8min ago
  Process: 3733 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 3737 (apache2)
    Tasks: 7 (limit: 4915)
   CGroup: /system.slice/apache2.service
           ├─3737 /usr/sbin/apache2 -k start
           ├─3738 /usr/sbin/apache2 -k start
           ├─3739 /usr/sbin/apache2 -k start
           ├─3740 /usr/sbin/apache2 -k start
           ├─3741 /usr/sbin/apache2 -k start
           ├─3742 /usr/sbin/apache2 -k start
           └─3743 /usr/sbin/apache2 -k start

12月 26 08:52:50 kali systemd[1]: Starting The Apache HTTP Server...
12月 26 08:52:50 kali apachectl[3733]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
12月 26 08:52:50 kali systemd[1]: Started The Apache HTTP Server.
這是成功啓動後的服務器狀態

服務器的根目錄是/var/www/html

於是乎寫一個shell方便下次使用

腳本判斷apache是否啓動,沒有啓動則啓動,然後在資源管理器中打開html文件所在路徑

#!/bin/bash

test=$(ps aux | grep apache2 | grep -v 'grep' | wc -l)
if [ $test -gt 0 ];then
	echo "$(date) httpd is running..."
else echo "$(date) httpd is not running...  starting ..."
	service apache2 start
fi

nautilus /var/www/html

echo 'run successfully...'
最終記得爲這個bash文件添加可執行權限


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章