八 Apache和PHP结合
httpd主配置文件/usr/local/apache2.4/conf/httpd.conf
vim /usr/local/apache2.4/conf/httpd.conf //修改以下几个地方
1.启动Apache会看到下面的警告,这并不是错误。
[root@gregory ~]# /usr/local/apache2.4/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::5ad6:bfd1:c8d:ed7a. Set the 'ServerName' directive globally to suppress this message
/usr/local/apache2.4/bin/apachectl: line 79: 2576 Segmentation fault $HTTPD -k $ARGV
解决:
1).把ServerName www.example.com:80前面的#去掉。
2).看PHP5和php7是否同时加载了。如果同时加载注释掉其中一个。
2.window浏览器打开ip地址192.168.179.128
如果打不开:
1)window控制面板à程序和功能à启用或关闭Windows功能à勾选Telnet客户端。
2)win+R,ping 192.168.179.128 80这时看能不能通。
3)如果不能通,在Linux添加80端口配置:iptables –I INPUT –p tcp –dport 80 –j ACCEPT,再ping就通了
3.修改Require all denied为granted。
<Directory />
AllowOverride none
Require all granted
</Directory>
目的是,允许所有请求,如果不设置该行,则我们访问的时候会包403错误。
/usr/local/apache2.4/bin/apachectl –t检查配置文件语法是否正确
/usr/local/apache2.4/bin/apachectl graceful重新加载配置文件,并不会重启服务。
4.增加AddType application/x-httpd-php .php
5.修改为DirectoryIndex index.html index.php
/usr/local/apache2.4/bin/apachectl -t //测试语法
/usr/local/apache2.4/bin/apachectl start //启动服务