为解决这个问题,花了一个下午,参考了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
一位同学在他的博客中对这个问题有详细说明,具体可以见链接
问题并没有解决。
继续探索
参考一位同学的[修改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
到这里,我不得不爆个粗口,*##$^%*,终于解决了。
如果以上都不行,或者报错是这样的:
apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2019-08-24 23:37:56 PST; 9s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 14755 ExecStart=/usr/sbin/apachectl start (code=exited, status=127)
Aug 24 23:37:56 user-E5-575G systemd[1]: Starting The Apache HTTP Server...
Aug 24 23:37:56 user-E5-575G apachectl[14755]: /usr/sbin/apachectl: 174: /usr/sbin/apachectl: /usr/sbin/apache2: not found
Aug 24 23:37:56 user-E5-575G apachectl[14755]: Action 'start' failed.
Aug 24 23:37:56 user-E5-575G apachectl[14755]: The Apache error log may have more information.
Aug 24 23:37:56 user-E5-575G systemd[1]: apache2.service: Control process exited, code=exited, status=127/n/a
Aug 24 23:37:56 user-E5-575G systemd[1]: apache2.service: Failed with result 'exit-code'.
Aug 24 23:37:56 user-E5-575G systemd[1]: Failed to start The Apache HTTP Server.
那么有可能是你的端口被占用了,比如我的可能就是之前用的nginx启动服务
占用了80端口,你可以用这个口令查看下,netstat -plant | grep 80,如果是,就需要把这个进程给干掉,指令:killall nginx,然后重新输入service apache2 start即可!你也可以再输入:ps -ef|grep apache2,或者:systemctl status apache2 查看服务情况。
原文链接:https://blog.csdn.net/dreamstone_xiaoqw/article/details/78088197