默认情况下,apache安装完成之后是没有办法直接解析PHP页面的,我们需要修改一下配置文件
1、启动httpd服务 (推荐学习:PHP视频教程)/usr/local/apache2.4/bin/apachectl start
2、默认没有修改配置文件的情况下,刚启动httpd的时候会报一个没有定义ServerName的提示,但并不影响httpd的正常启动AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
3、修改配置文件cp /usr/local/apache2.4/conf/httpd.conf /usr/local/apache2.4/conf/httpd.conf.bak //修改任何配置文件,先拷贝一份副本
vim /usr/local/apache2.4/conf/httpd.conf +195
ServerName www.example.com:80//在任意处新增一段ServerName
默认情况下httpd只允许用户访问欢迎页面目录下的文件,访问其他httpd目录都是403,这是由于httpd默认规则是denied,我们需要改成grantedvim /usr/local/apache2.4/conf/httpd.conf
把
AllowOverride none
Require all deined
改成:
AllowOverride none
Require all granted
默认情况下httpd不支持解析php页面,为了能让httpd与php结合,需要新增一些配置内容
AddType application/x-httpd-php .php
还需要增加一个目录索引
DirectoryIndex index.html index.php
以上修改完成之后保存退出
4、当我们修改完配置文件后,需要检查一下是否有语法错误然后再进行重启等操作/usr/local/apache2.4/bin/apachectl -t//使用-t检查语法,出现Syntax OK 说明配置文件没有错误
5、让httpd配置文件生效有两种方法1)/usr/local/apache2.4/bin/apachectl restart//重启启动httpd服务
2)/usr/local/apache2.4/bin/apachectl graceful //只重新加载配置文件,不重启httpd服务
6、编写一个php测试脚本,检测httpd是否能够解析php页面(默认页面存放路径是在/usr/local/apache2.4/htdocs目录下)vim /usr/local/apache2.4/htdocs/test.php
phpinfo();
?>
7、浏览器输入自己服务器的IP地址+php页面名称,出现以下页面说明httpd解析php页面正常