[root@localhost httpd]# vim conf/httpd.conf
~
这里安装了两个php模块,需要注释掉一个php模块。因为httpd不能同时加载两个php模块
LoadModule php5_module modules/libphp5.so
#LoadModule php7_module modules/libphp7.so
将ServerName行的注释去掉,这样可以使httpd能够正常启动和访问默认页
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
ServerName www.example.com:80
修改默认的目录策略,denied表示拒绝访问网页目录,granted表示允许访问网页目录,防止打开虚拟主机配置会显示网页报错状态码403
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# blocks below.
#
AllowOverride none
Require all granted
网页根目录的配置路径及权限配置,Require all granted这里配置和上面的目录访问有关联的作用,表示网页目录是否能够有权限访问
DocumentRoot "/usr/local/httpd/htdocs"
Options Indexes FollowSymLinks
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
AllowOverride None
# Controls who can get stuff from this server.
Require all granted
添加php的解析主页,添加php的解析主页,在访问时才能对php页面正确识别
DirectoryIndex index.html index.php
添加php解析的配置项,httpd中必须添加解析配置项才能让httpd的php解析请求发送到php模块进行解析
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
检查httpd配置文件是否正确,测试配置内容,这里注意的是一个使用习惯,在修改配置文件后首先检查配置文件中是否有错误,如果配置文件中配置有误而不检查直接重新启动服务,会造成服务启动时的报错服务启动终止,导致服务对外停止提供访问,这样会造成短时间内服务无法访问的情况,需要检查配置文件后并重启服务,使用graceful对服务重新加载配置即可