0

我正在使用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 服务器上运行良好,我试图在本地托管它以实现版本控制,以便我可以在本地开发并将更改推送到服务器。

4

1 回答 1

2

If you put your include/ folder into this folder;

/Users/jfloyd/IOD/includes/<all in here>

Then alter this line in your PHP ini from:

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

TO

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

Then save the file and restart your server, then the include files should be found.

This ini directive can be set in any number of places, in each file, in each folder using .htaccess or in httpd.conf or in the ini file, as I just described.

于 2013-04-23T15:17:22.923 回答