I have file structure on EC2 like : but facing some file referencing problem.
index.php
-db
-config.php
-cron
-cron1.php
I have tried file referencing as:
`require_once (dirname(__FILE__).'/db/config.php');`
`require_once (($_SERVER['DOCUMENT_ROOT']).'/db/config.php');`
but cron doesn't run.it gives error in mail as
`PHP Warning: require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3
Warning: require_once(/db/config.php): failed to open stream: No such file or directory in /var/www/html/cron/cron1.php on line 3
PHP Fatal error: require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3
Fatal error: require_once(): Failed opening required '/db/config.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/cron/cron1.php on line 3`
I had the same error while including file from root of my project in
codeigniter
.I was using this incommon.php
of my project.i changed it to
Working fine now.
Thats just the directories showing you where PHP was looking for your file. Make sure that
cron1.php
exists where you think it does. And make sure you know wheredirname(__FILE__)
and$_SERVER['DOCUMENT_ROOT']
are pointing where you'd expect.This value can be adjusted in your php.ini file.
If you look at the PHP constant PATH_SEPARATOR, you will see it being ":" for you.
If you break apart your string ".:/usr/share/pear:/usr/share/php" using that character, you will get 3 parts
Any attempts to include()/require() things, will look in these directories, in this order.
It is showing you that in the error message to let you know where it could NOT find the file you were trying to require()
For your first require, if that is being included from your index.php, then you dont need the dir stuff, just do:
I had a similar problem. Just to help out someone with the same issue:
My error was the user file attribute for the files in /var/www. After changing them back to the user "www-data", the problem was gone.
Solution to the problem
as mentioned by Uberfuzzy [ real cause of problem ]
If you look at the PHP constant [PATH_SEPARATOR][1], you will see it being ":" for you.
If you break apart your string ".:/usr/share/pear:/usr/share/php" using that character, you will get 3 parts
Any attempts to include()/require() things, will look in these directories, in this order.
It is showing you that in the error message to let you know where it could NOT find the file you were trying to require()
That was the cause of error.
Now coming to solution
php --ini
( in my case :/etc/php5/cli/php.ini
)include_path
in vi usingesc
then press/include_path
thenenter
include_path = ".:/usr/share/php:/var/www/<directory>/"
sudo service apache2 restart
This is it. Hope it helps.
Actually, the solutions is to open the php.ini file edit the include_path line and either completely change it to
or append the
to the current value of include_path.
It is further explained in : http://pear.php.net/manual/en/installation.checking.php#installation.checking.cli.phpdir