游览器找不到服务器上PHP文件的一种原因

最近在练习搭建网站,遇到游览器找不到服务器上的php文件的问题。后来查找发现,apache文档根目录跟apache虚拟主机文档根目录不同,服务器开启了虚拟主机功能。这导致游览器找不到php文件。

使用的环境是LAMP,它 的操作系统和软件版本如下:CentOS 7.8 64bit,Apache 2.4.46 ,MariaDB 10.5.9,PHP 7.4.29 。

可以修过虚拟主机的文档根地址来处理这个问题。或者不开启虚拟主机功能。

注意!:/home/www/htdxxx只是目录名的一个示意名,具体要根据计算机的实际来设置。

1、apache 的 httpd.conf 文件部分内容

1.1、apache文件根目录

DocumentRoot "/home/www/htdxxx"
<Directory "/home/www/htdxxx">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

1.2、是否包含vhost.conf。这里设置了不包含该文件

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf

1.3、目录索引(DirectoryIndex)。index.html与index.php的位置影响网站的网页能否正常显示。

# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

2、httpd-vhosts.conf文件部分内容

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/home/www/htdxxx/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ......     # 备注:省略了几行
</VirtualHost>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值