Ubuntu中Apache2啟動失敗報錯Job for apache2.service failed because the cont...
阿新 • • 發佈:2019-02-08
為解決這個問題,花了一個下午,參考了120多條網路博文,很有成就感。但實際上是由於一個簡單的配置原因導致的問題,希望以後可以更加細心。
目錄
- 最初的現象,php程式碼沒有解析
phpinfo輸出內容是
<?php
phpinfo();
?>
顯然,只是程式碼,並沒有成功解析php程式碼。事後分析,是Apache2服務的問題。
- 禁用ipv6網段
Job for apache2.service failed because the control process exited with error code.
See “systemctl status apache2.service” and “journalctl -xe” for details.
原因是沒有禁用ipv6網段。
在CentOS環境下也是需要禁用的。
vim /etc/hosts
註釋掉以下內容:
# The following lines are desirable for IPv6 capable hosts
#::1 ip6-localhost ip6-loopback
#fe00::0 ip6-localnet
#ff00::0 ip6-mcastprefix
#ff02::1 ip6-allnodes
#ff02::2 ip6-allrouters
問題並沒有解決。
- 繼續探索
cd /etc/apache2
sudo vim apache2.conf
在檔案末尾加入下面的命令
ServerName localhost:80
DirectoryIndex index.html index.htm index.php
AddDefaultCharest GB2312
並沒有用。
- 真正解決問題
仔細分析日誌,根據提示,systemctl status apache2.service
說:
Sep 25 15:13:01 ubuntu apachectl[4756]: apache2: Syntax error on line 147 of /etc/apache2/apache2.conf: Could not open config directory /var/www/html/mods-enabled: No such file or directory
我看了下,之前我有把mods-enabled拷貝呀,很奇怪。在折騰了很久之後,我才想起來看下里面到底是什麼東西。
xiaoqw@vm:~$ ls /var/www/html/mods-enabled/ -l
這才發現mods-enabled檔案目錄中全部都是符號連結,所以複製目錄是行不通的。
所以,試試符號連結。
$ cd /var/www/html/
$ ln -s /etc/apache2/mods-enabled
#為了保險期間,再加一個
$ ln -s /etc/apache2/mods-available
注意:這時,換錯誤啦!說明之前的問題已經解決。
Sep 25 18:14:08 ubuntu apachectl[5226]: apache2: Syntax error on line 151 of /etc/apache2/apache2.conf: Could not open configuration file /var/www/html/ports.conf: No such file or directory
缺少ports.conf檔案,即埠配置檔案。再做個連結:
$ cd /var/www/html/
$ ln -s /etc/apache2/ports.conf
換錯誤,重複解決方法:
$ ln -s /etc/apache2/conf-enabled
$ ln -s /etc/apache2/sites-enabled
到這裡,我不得不爆個粗口,**##*$^%*
,終於解決了。
配個圖: