【问题标题】:Could not find .php file in /var/www in apache server在 apache 服务器的 /var/www 中找不到 .php 文件
【发布时间】:2022-01-26 10:34:09
【问题描述】:

我正在为服务器使用 Vagrant 提供程序,现在查看我的目录:

在我的系统中:

https://i.stack.imgur.com/XCXIm.png

流浪者网站
-项目(/var/www)
--public (/var/www/html)
---index.php

现在我在 Project 文件夹中创建了一个示例 .php 文件,然后当我运行 vagrant 并在我 cd 到 /var/www 时登录 vagrant ssh 时,那个 .php 文件不存在并且我无法使用

include __DIR__ . '/../count.html.php';

这行代码不起作用,因为该文件在 /var/www 中不存在,但在我的系统中存在

那个 index.php 文件它的工作没有问题,但我想在公共目录之外创建一个 php 文件,只有我自己可以访问它,现在当我在 Project 文件夹中创建该文件时,现在这个文件必须在 /var/www 里面,当我在我的 php 代码中使用 include 命令时,php 找不到,我使用了 file_exists() 函数并给出了 php 文件函数的路径,现在函数返回 false 然后我检查 /var/www检查php文件是否存在的目录,不存在!

【问题讨论】:

  • 您是否检查了 /var/www/html 中的项目文件夹

标签: php linux vagrant apache2 ubuntu-20.04


【解决方案1】:

我解决了问题,
在同步文件夹配置部分的 vagrant 文件中,我发现我可以添加更多目录,所以我同步了:./Project 到 /var/www 但请记住, 同步后它会改变的东西,这个目录:/var/www/html, apache2 中的那个 html 文件夹将删除并替换为您的公共目录名称(在您的设备内,对我来说它是公共的)public directory folder, 现在您需要在此路径中更改 000-default.conf 文件中的根目录地址:/etc/apache2/sites-available/000-default.conf 更改此重启 apache2 服务后

DocumentRoot /var/www/html change this => /var/www/your public directory name  

sudo service apache2 restart

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-07
    • 2016-03-29
    • 2019-11-11
    • 1970-01-01
    • 2016-04-15
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多