【问题标题】:Trouble with local host PHP require_once本地主机 PHP require_once 出现问题
【发布时间】:2013-04-23 23:17:22
【问题描述】:

我正在使用 MAMP 在本地托管一个网站。我已经正确设置了虚拟主机,并且当我引用本地 URL 时 index.php 文件确实被拉起:my.example.local

问题是 PHP 文件包含不起作用。以下是代码示例:

<?php
session_start();
$_SESSION['message'] = '';
require_once "includes/config.php";
require_once "includes/classes/facilities.class.php";
require_once "includes/classes/states.class.php";
$title = "Home";
$sub_title = $title;
$reset = false;
require_once "includes/header.php";
?>

这是我在访问 index.php 时收到的错误消息:

Warning: require_once(includes/classes/facilities.class.php): failed to open stream: No such file or directory in /Users/userName/IOD/portal/index.php on line 9    
Fatal error: require_once(): Failed opening required 'includes/classes/facilities.class.php' (include_path='.:/Applications/MAMP/bin/php/php5.4.10/lib/php') in /Users/userName/IOD/portal/index.php on line 9

作为记录,我尝试了多种不同的方式来引用文件路径、相对、绝对、使用主机名等。

我愿意尝试任何事情,但到目前为止还没有运气。哦,在你问之前,是的,文件在引用的位置,但由于某种原因,(本地)服务器似乎不认为它们是。

注意:这在 Web 服务器上运行良好,我试图在本地托管它以实现版本控制,以便我可以在本地开发并将更改推送到服务器。

【问题讨论】:

  • 第一个require_once没有错误?如果注释掉facility.class.php 的require_once,states.class.php 的require_once 会失败吗?
  • 会不会是文件权限错误?不确定 MAMP,但是在 LAMP 堆栈上,您和 apache 用户(通常是 www-data)最初不在同一个组中的情况经常发生
  • 您应该检查该文件是否真的存在并且是否可读。查看is_file('includes/classes/facilities.class.php')is_readable('includes/classes/facilities.class.php')

标签: php localhost mamp


【解决方案1】:

如果你把你的 include/ 文件夹放到这个文件夹中;

/Users/jfloyd/IOD/includes/&lt;all in here&gt;

然后将 PHP ini 中的这一行更改为:

include_path='.:/Applications/MAMP/bin/php/php5.4.10/lib/php'

include_path='.:/Applications/MAMP/bin/php/php5.4.10/lib/php:/Users/jfloyd/IOD/'

然后保存文件并重新启动服务器,然后应该找到包含文件。

这个 ini 指令可以设置在任意数量的位置,在每个文件中,在每个文件夹中使用 .htaccess 或在 httpd.conf 或 ini 文件中,正如我刚刚描述的那样。

【讨论】:

  • 好的,更新,你可以通过几种方式解决这个问题。 Cups 的上述方法将起作用,但它要求您为多个域输入多个条目。我所做的是直接进入目录标签下的 apache httpd.conf 文件,如下所示:&lt;Directory "/Users/userName/IOD/portal"&gt; php_value include_path ".:/Users/userName/your/includes/folder:/Users/userName/your/includes/folder/classes" AllowOverride All Order allow,deny Allow from all &lt;/Directory&gt;
猜你喜欢
  • 2013-12-24
  • 1970-01-01
  • 1970-01-01
  • 2020-08-05
  • 1970-01-01
  • 2015-06-05
  • 2012-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多