Trouble with local host PHP require_once

时光怂恿深爱的人放手 提交于 2019-12-13 06:18:48

问题


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

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";
?>

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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/16172982/trouble-with-local-host-php-require-once

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!