Hi I am getting this error, when I run the index.php file which includes
require_once("system/config.php");
I am wondering what does this message mean, and how do I go about fixing such an issue. As this site worked fine when I ran it directly on my Mac.
require_once(): Failed opening required 'system/core.php' (include_path='.:/usr/share/php')
ALL THE BELOW ANSWERS ARE CORRECT!
However my issue was a CHMOD issue I had 644 instead of 744
It usually means you're trying to include the file with an incorrect path. What happens when you try the full path?
require_once(getcwd() . 'system/config.php');
The way your script is now, it's looking for the file with a directory structure like this:
file.php <- is calling the require_once()
- system <- the system directory
- config.php <- the config file
But this isn't the path where it's located.
The file system/core.php needs to be relatively to the file which is declaring the line require_once("system/core.php"); (that's system/config.php) or the direcory that contains system must be in your include_path. Search for core.php on your Mac. Check the configuration settings (include_path) on your Mac.
Related
I want to include a file that is in a parent folder in my php code using:
include('../defines.php');
However when I deploy to heroku from CLI and run my php file it gives me this error.
PHP Warning: include(): Failed opening '../defines.php' for inclusion (include_path='.:/app/.heroku/php/lib/php') in /app/workers/test.php on line 2
If I run locally from my installed Wamp 3.1.4 server it run fines without issues.
I can make it work if I remove the `../? from the path. But that seems wrong.
Another way I've found on github is doing
include __DIR__ . '/../defines.php';
But i think doing it that way would be using absolute, not relative path.
Is there something i'm missing?
<?php
include('../defines.php');
?>
Folder tree:
www/
defines.php
workers/
test.php
It's depending how you classified your folder.
Maybe you can try this :
require("/../yourFolder.php");
Im runninng lamp stack locally on my ubuntu 16.04 OS and Im getting problems when including files. My code in index.php:
<?php include('steamauth/steamauth.php'); ?>
<?php include('steamauth/userinfo.php');?>
my structure is:
index.php
steamauth
steamauth.php
userinfo.php
Im getting the following error:
include(steamauth/userinfo.php): failed to open stream: No such file or directory in /var/www/html/index.php
include(): Failed opening 'steamauth/userinfo.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/index.php
I tried using the full path , adding webroot before the path , changing include_path in php.ini , but nothing seemed to work . what do i do ?
Check folder pemission
Check that the Apache user has access to the include folder.
Check file permissions
Check that the permissions on the files that you are including can be read and executed by the Apache user.
Check PHP settings
It could be caused by one of the following PHP settings:
open_basedir:
If this is set PHP won't be able to access any file outside of the specified directory (not even through a symbolic link).
safe mode:
If this is turned on restrictions might apply.
Make path absolute
Check that $_SERVER["DOCUMENT_ROOT"] is correctly set for your domain by using:
print $_SERVER["DOCUMENT_ROOT"]; // Add to top of you index.php file.
Then change your includes to:
$_SERVER["DOCUMENT_ROOT"] . '/sub_folder/file_to_include';
Check for typos and spelling mistakes
Carefully check that what you think you have called the folder and what you are using to include it are spelt the same.
BTW: You can just use the following in your index.php file:
<?php
include('steamauth/steamauth.php');
include('steamauth/userinfo.php');
You also don't need to add the closing ?> at the end of the file - it's actually good practice not to.
I have uploaded all my files in var/www/html and in one of my php files I have this line :
require_once('libraries/stripe/init.php');
the structure of my folders are list this:
www
-html/
-libraries
-> Stripe -> init.php
-register.php
I keep getting this error message:
Warning: require_once(libraries/Stripe/init.php): failed to open stream: No such file or directory in /var/www/html/register.php on line 116
Fatal error: require_once(): Failed opening required 'libraries/Stripe/init.php' (include_path='.:/usr/share/php:/var/www/html/') in /var/www/html/register.php on line 116
my php.ini file used to be like this
include_path= ".:/usr/local/php/pear/"
but based on some answers here i changed it to
include_path='.:/usr/share/php:/var/www/html/'
but it's not working!
Edit: in my libraries folder I have file called index.php the content is:
<?php
header("Location: ../"); die();
I wouldn't leave library paths to chance like that:
require_once(__DIR__ . '/libraries/Stripe/init.php');
This would make sure you include the script using the absolute directory path of the currently running script.
Update
Failed opening required '/var/www/html/libraries/Stripe/init.php'
Well, then the file is simply not there; if this file was generated by some other tool, e.g. composer, it would need to be done again on a new server (or ideally at every deployment).
i think the problem is my Stripe folder is in "s" but I'm using capital "S". is there anyway to make not case sensitive?
File systems under Linux are case sensitive by default (not even sure whether it can be changed) as opposed to Windows. Make sure you use capitalisation consistently.
That not what you are looking for. it says that php.ini file can't find the path of the file that you specified. that's why you should use absolute path to the file
require_once "path/to/file";
I tried to reorganise my facebook application files into better folders and now when I try to load my application on facebook it throws the following error:
Warning: require_once(../scripts/mysql_connect.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
Fatal error: require_once() [function.require]: Failed opening required '../scripts/mysql_connect.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
The second error is a result of the failure of the first one I think. The weird thing is that my program works perfectly fine when I'm accessing through the localhost url in the browser but when I run it through facebook it throws this error.
In my root folder I have a "Model" folder where the Database.php file is kept and a "scripts" folder where the mysql_connect.php file is kept. I have tried clearing my cache on the browser and using private browsing but it is still throwing this error.
Does anyone know what could be wrong?
EDIT: Sorry this does not seem to be working in localhost either now! One thing I think is weird is that it says "failed to open stream : NO SUCH FILE OR DIRECTORY IN" and then lists the database.php path. Why is it looking in there?
I use the line require_once('../scripts/mysql_connect.php'); at the top of my Database.php file to include it.
It seems that on the server there is a different working directory. Something like the following owuld be a quick fix
dirname(__FILE__) . '/../scripts/mysql_connect.php'
Ok I've fixed this, but I'm still unsure why it was a problem. In my root folder I have two folders: scripts, and Model. I have a database.php file in my Model folder which has the following line of code in:
require_once('../scripts/mysql_connect.php');
For some reason this did not work, but by replacing the line with:
require_once('/scripts/mysql_connect.php');
This started working again! Just thought I would post the solution. Does anyone know why the other way failed? I thought the ".." just makes it go up one level in the folder hierarchy i.e. to the root folder in this case, and then follow the path which would have taken it to the file...
EDIT: This appears to only have solved it for localhost and not through Facebook...
Do you have permission to edit your php.ini file? One solution would be to find the line with the include path (you'll notice it has C:\xampp\php\PEAR in there already). Include the full path to the "scripts" folder you're referencing, then you can change the php code to read:
require_once('mysql_connect.php');
PHP will be able to find this file since it's in the include path. Just make sure that if you start adding several include paths that you shouldn't have a file named mysql_connect.php in two or more of the different include paths because you'll most likely get errors. Hope this helps. It definitely makes for some cleaner code.
I have a PHP file /a/b/file.php with the line
require("../connect.php");
In connect.php there is a line
require("../config.inc.php");
This all works fine on my local server. There are a bunch of files using connect.php and they all work fine too.
However on the hosting site /a/b/file.php throws an error:
Fatal error: require() [function.require]: Failed opening required
'../config.inc.php' (include_path='.:/usr/local/php5/lib/php') in
/******/connect.php on line 3
I suspect that even though connect.php is in another folder, it's looking for it relative to /a/b. Is there a php.ini setting to change this?
Why dont you use something like:
require( dirname(__FILE__).DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."connect.php");
This way you will avoid problems like when you develop an app on a Unix-Like system and deploy it on a Windows systems, or viceversa.
I don't know if there's a php.ini setting, but usually I use $_SERVER['DOCUMENT_ROOT'] for my included files.
require $_SERVER['DOCUMENT_ROOT']."/path/relative/to/document_root/file.php";
There are some cases where a relative path is better, but most of the time the files you want to include will stay in the same dir.
Usually I personally make a file called global.php (which is in the root directory of the project) where I define() a constant, include libs and so on.
<?php
// ...
define('APP_INCLUDE_DIR', dirname(__FILE__) .'/');
// ...
?>
Afterwards I include that file in all other files located in the same directory (e.g. index.php with require('global.php'). Now that everything is executed at that directory level you can use the constant APP_INCLUDE_DIR in every file which gets included.
<?php
require('global.php');
// ...
require_once(APP_INCLUDE_DIR .'a/b/c/connect.php');
?>
And in a/b/c/connect.php you could write for example
<?php
// ...
require_once(APP_INCLUDE_DIR .'a/b/config.inc.php');
?>
Check your include_path in your PHP.ini file.
http://php.net/manual/en/function.set-include-path.php
For example, on my local server (XAMPP) it looks like this: `include_path .;C:\xampp\php\PEAR
You can do a phpinfo() to find out also.