Ubuntu中Apache2启动失败报错Job for apache2.service failed because the cont... 为解决这个问题,花了一个下午,参考了120多条网络博文,很有成就感。但实际上是由于一个简单的配置原因导致的问题,希望以后可以更加细心。
phpinfo输出内容是
显然,只是代码,并没有成功解析php代码。事后分析,是Apache2服务的问题。
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
一位同学在他的博客中对这个问题有详细说明,具体可以见链接 问题并没有解决。
参考一位同学的[修改apache的配置文件]教程。 (http://blog.csdn.net/jenyzhang/article/details/51539165)
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
**##*$^%*
,终于解决了。