本文介绍了本地主机PHP require_once遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MAMP 在本地托管网站.我正确设置了虚拟主机,当我引用本地URL:my.example.local

I am hosting a site locally with MAMP. I have the virtual host setup properly and the index.php file does get pulled up when i reference the local URL: my.example.local

问题是包含的PHP文件不起作用.这是代码示例:

The issue is that the PHP file includes are not working. Here is a sample of the code:

<?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时收到的错误消息:

and here is the error message i get when accessing 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

为了进行记录,我尝试了多种不同的方式来引用文件路径,包括相对,绝对,使用主机名等.

For the record I have tried multiple different ways of referencing the file path, relative, absolute, using the host name, etc.

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

I am willing to try anything but haven't had any luck so far. Oh and before you ask, yes the files are in the referenced location but for some reason the (local)server doesn't seem to think they are.

注意:这在Web服务器上工作正常,我试图在本地托管它以实现版本控制,以便我可以在本地Dev并将更改推送到服务器.

Note: this works fine on the web server, I was trying to host it locally to implement version control so I can Dev locally and push changes to the server.

推荐答案

如果将include/文件夹放入此文件夹;

If you put your include/ folder into this folder;

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

然后从以下位置更改PHP ini中的这一行:

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.

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

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.

这篇关于本地主机PHP require_once遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:59