Apache,問題無法啟動 LSB:Apache2 Web 伺服器

Apache,問題無法啟動 LSB:Apache2 Web 伺服器

我使用Ubuntu 16.02。當我嘗試時sudo service apache2 restart,它說:

Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

然後我輸入:journalctl -xe,並請求:

--
-- apache2.service 單元已開始啟動。
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/etc/init.d/apache2:1:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/etc/init.d/apache2:49:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/etc/init.d/apache2:1:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/etc/init.d/apache2:49:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: * 啟動 Apache httpd Web 伺服器 apache2
1 月 11 日 02:30:46 亞歷山大-VirtualBox apache2[8177]:*
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: * apache2 設定測試失敗。
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:設定測試的輸出為:
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/usr/sbin/apache2ctl:1:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/usr/sbin/apache2ctl:49:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)沒有這樣的檔案或目錄: AH02291: 無法存取主錯誤日誌目錄 '/etc/apache2/logs/'
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:AH00014:設定檢查失敗
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:操作「configtest」失敗。
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:Apache 錯誤日誌可能包含更多資訊。
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:apache2.service:控制進程已退出,代碼=退出狀態=1
Jan 11 02:30:46 aleksandr-VirtualBox sudo[8171]:pam_unix(sudo:session):使用者 root 的會話已關閉
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:無法啟動 LSB:Apache2 Web 伺服器。
-- 主題: apa​​che2.service 單元失敗
-- 定義者:systemd
-- 支援:http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- apache2.service 單元失敗。
--
——結果失敗了。
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:apache2.service:單元進入失敗狀態。
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:apache2.service:失敗,結果為「退出代碼」。
Jan 11 02:33:09 aleksandr-VirtualBox dhclient[792]:enp0s8 上的 192.168.56.101 的 DHCPREQUEST 到 192.168.56.100 埠 67 (xid=0x20f)
Jan 11 02:33:09 aleksandr-VirtualBox dhclient[792]:來自 192.168.56.100 的 192.168.56.101 的 DHCPACK
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:[1484073189.4253]地址192.168.56.101
1 月 11 日 02:33:09 亞歷山大-VirtualBox NetworkManager[619]: [1484073189.4260] plen 24 (255.255.255.0)
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:[1484073189.4266]伺服器識別碼 192.168.56.100
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:[1484073189.4273] 租賃時間 1200
Jan 11 02:33:09 aleksandr-VirtualBox NetworkManager[619]:[1484073189.4279] dhcp4(enp0s8):狀態變更綁定 - >綁定
Jan 11 02:33:09 aleksandr-VirtualBox dbus[590]:[系統]透過 systemd 啟動:服務名稱='org.freedesktop.nm_dispatcher'unit='dbus-org.freedesktop.nm-dispatcher.service'
Jan 11 02:33:09 aleksandr-VirtualBox systemd[1]:啟動網路管理器腳本調度程式服務...
-- 主題:Unit NetworkManager-dispatcher.service 已開始啟動
-- 定義者:systemd
- 支持:
--
-- Unit NetworkManager-dispatcher.service 已開始啟動。
Jan 11 02:33:09 aleksandr-VirtualBox dhclient[792]:綁定到 192.168.56.101 —— 559 秒內更新。
Jan 11 02:33:09 aleksandr-VirtualBox dbus[590]:[系統] 已成功啟動服務“org.freedesktop.nm_dispatcher”
Jan 11 02:33:09 aleksandr-VirtualBox systemd[1]:啟動網路管理器腳本調度程式服務。
-- 主題:Unit NetworkManager-dispatcher.service 已完成啟動
-- 定義者:systemd
- 支持:
--
-- Unit NetworkManager-dispatcher.service 已完成啟動。
--
-- 啟動結果完成。
Jan 11 02:33:09 aleksandr-VirtualBox nm-dispatcher[8205]:req:1'dhcp4-change'[enp0s8]:新請求(1個腳本)
Jan 11 02:33:09 aleksandr-VirtualBox nm-dispatcher[8205]: req:1 'dhcp4-change' [enp0s8]: 開始執行有序腳本...

systemctl status apache2.service它需要時:

* apache2.service - LSB:Apache2 Web 伺服器
   已載入:已載入(/etc/init.d/apache2;壞;供應商預設:已啟用)
  插入:/lib/systemd/system/apache2.service.d
           `-apache2-systemd.conf
   活動:失敗(結果:退出代碼)自 2017 年 1 月 11 日星期三 02:30:46 +08 起; 33 分鐘前
     文件: man:systemd-sysv-generator(8)
  進程:8023 ExecStop=/etc/init.d/apache2 stop(代碼=已退出,狀態=0/SUCCESS)
  進程:2236 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  進程:8177 ExecStart=/etc/init.d/apache2 start(代碼=已退出,狀態=1/FAILURE)

Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/usr/sbin/apache2ctl:1:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:/usr/sbin/apache2ctl:49:/etc/apache2/envvars:envvars:找不到
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)沒有這樣的檔案或目錄: AH02291: 無法存取主錯誤日誌目錄 '/etc/apache2/logs/'
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:AH00014:設定檢查失敗
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:操作「configtest」失敗。
Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]:Apache 錯誤日誌可能包含更多資訊。
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:apache2.service:控制進程已退出,代碼=退出狀態=1
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:無法啟動 LSB:Apache2 Web 伺服器。
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:apache2.service:單元進入失敗狀態。
Jan 11 02:30:46 aleksandr-VirtualBox systemd[1]:apache2.service:失敗,結果為「退出代碼」。

怎麼了?哪裡有中斷?請幫忙!

答案1

有兩個錯誤:


1.由於某種原因你/etc/apache2/envvars失蹤了:

  • journalctl -xe

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /etc/init.d/apache2: 49: /etc/apache2/envvars: envvars: not found
    ...        
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found
    
  • systemctl status apache2.service

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 1: /etc/apache2/envvars: envvars: not found
    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: /usr/sbin/apache2ctl: 49: /etc/apache2/envvars: envvars: not found
    

在我的系統中,該檔案具有以下權限:

$ ls -l /etc/apache2/envvars

-rw-r--r--   1 root root  1782 мар 19  2016 envvars

其內容( $ cat /etc/apache2/envvars)為:

# envvars - default environment variables for apache2ctl

# this won't be correct after changing uid
unset HOME

# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
        SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
        SUFFIX=
fi

# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
# temporary state file location. This might be changed to /run in Wheezy+1
export APACHE_PID_FILE=/var/run/apache2/apache2$SUFFIX.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX

## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale

export LANG

## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'

## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'

## If you would like to pass arguments to the web server, add them below
## to the APACHE_ARGUMENTS environment.
#export APACHE_ARGUMENTS=''

## Enable the debug mode for maintainer scripts.
## This will produce a verbose output on package installations of web server mod                                               ules and web application
## installations which interact with Apache
#export APACHE2_MAINTSCRIPT_DEBUG=1

您可以手動建立:sudo nano /etc/apache2/envvars,將上面的內容貼到裡面,儲存ctrl+o並退出ctrl+ x


2.在您的系統中,/etc/apache2/logs也缺少該資料夾:

  • journalctl -xe

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log
    
  • systemctl status apache2.service

    Jan 11 02:30:46 aleksandr-VirtualBox apache2[8177]: (2)No such file or directory: AH02291: Cannot access directory '/etc/apache2/logs/' for main error log
    

這不是預設的日誌資料夾,它是在您的自訂配置中定義的,必須建立:

$ sudo mkdir /etc/apache2/logs

答案2

我刪除了sites-available中的.conf文件,但沒有刪除sites-enabled中的連結文件。

現在我刪除了啟用網站中的所有文件

重新啟動 apache2 伺服器(sudo service apache2 restart)

為我工作

希望這可以幫助某人:)

答案3

我有同樣的問題。我在sudo service apache2 restart運行時遇到了同樣的錯誤sudo systemctl status apache2.service,紅線是Failed to start LSB: Apache2 web server.

解決方案

運行以下命令:

sudo apache2ctl configtest

它會檢查錯誤(我認為是語法錯誤),然後您可以調試錯誤。

答案4

就我而言,我這樣做:

解除安裝並刪除 Apache2

sudo service apache2 stop

sudo apt-get purge apache2

sudo apt-get autoremove

whereis apache2

sudo rm -rf /etc/apache2

重新安裝阿帕契2

sudo apt-get install apache2

sudo apache2ctl configtest

它為我奔跑

相關內容