本文共 3626 字,大约阅读时间需要 12 分钟。
1 配置httpd支持php
httpd主配文件:
/usr/local/apache2/conf/httpd.conf
2 vim /usr/local/apache2/conf/httpd/conf
root@localhost ~]# vim /usr/local/apache2.4/conf/httpd.conf
//修改以下4个地方 ServerName 开启 Require all denied
[root@localhost ~]# vim /usr/local/apache2.4/conf/httpd.conf AddType application/x-httpd-php.php
在此添加“AddType application/x-httpd-php .php”,意思是允许PHP服务解析该服务器。
Directorylndex index.html index.php 增加索引页
3 /usr/local/apache2.4/bin/apachectl -t //测试语法
[root@localhost ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK
4 /usr/local/apache2.4/bin/apachectl start //启动服务
[root@localhost ~]# /usr/local/apache2.4/bin/apachectl graceful
//注:该命令只是加载配置文件的内容
5 netstat -lntp //查看是否有监听端口[root@localhost ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
//防火墙添加允许规则6 curl localhost //模拟访问
7 vim /usr/local/apache2.4/htodcs/1.php //增加如下内容
[root@localhost ~]# vim /usr/local/apache2.4/htodcs/1.php
[root@localhost ~]# vim /usr/local/apache2.4/htdocs/phpinfo.php
#可以解析PHP代码,如果不支持,访问该文件时会显示源代码。
如果服务器无法解析PHP代码: 解决方法: 1. 检查Apache是否加载PHP模块 2. 检查系统中有没有PHP模块 3. 检查Apache配置文件中是否有错误或者没有加载PHP的配置[root@localhost ~]# vim /usr/local/apache2.4/htdocs/1.php
#phpinfo() 在访问该地址时,直接打印PHP的相关信息
8 curl localhost/test.php[root@localhost ~]# curl localhost/1.php123
[root@localhost ~]# vim /usr/local/apache2/conf/conf/httpd.conf# Virtual hostsInclude conf/extra/httpd-vhosts.conf# Local access to the Apache HTTP Server Manual#Include conf/extra/httpd-manual.conf# Distributed authoring and versioning (WebDAV)#Include conf/extra/httpd-dav.conf:wq
1 编辑虚拟主机配置文件
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf //改为如下ServerAdmin webmaster@abc.com DocumentRoot "/home/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com www.123.com ErrorLog "logs/abc.com-error_log" customLog "logs/abc.com-access_log" common ServerAdmin webmaster@111.com DocumentRoot "/home/wwwroot/111.com" ServerName 111.com ServerAlias www.123.cn ErrorLog "logs/111.com-error_log" CustomLog "logs/111.com-access_log" common
2 修改目录权限
AllowOverride none Require all denied#如果不想对上面做设置,那就需要在下面对虚拟机的文件目录做设置,不然403 AllowOverride none Require all granted
3 测试
[root@localhost home]# curl -x127.0.0.1:80 abc.comabc.com[root@localhost home]# curl -x127.0.0.1:80 111.com111.com[root@localhost home]# curl -x127.0.0.1:80 www.abcd.comabc.com[root@localhost home]# curl -x127.0.0.1:80 123.comabc.com[root@localhost home]# curl -x127.0.0.1:80 111.com111.com[root@localhost home]# curl -x127.0.0.1:80 localhostabc.com[root@localhost home]# curl -x127.0.0.1:80 www.12.cnabc.com[root@localhost home]# curl -x127.0.0.1:80 www.123.cn111.com[root@localhost home]# curl -x127.0.0.1:80 www.111.comabc.com[root@localhost home]# curl -x127.0.0.1:80 www.123.cn111.com[root@localhost home]#
转载于:https://blog.51cto.com/235571/2117239