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
Many developers include files by pointing to a remote URL, even if the file is within the local system. For example:
<php include("http://example.com/includes/example_include.php"); ?>
With allow_url_include disabled, this method does not work. Instead, the file must be included with a local path, and there are three methods of doing this:
By using a relative path, such as ../includes/example_include.php
.
By using an absolute path (also known as relative-from-root), such as /home/username/example.com/includes/example_include.php.
By using the PHP environment variable $_SERVER['DOCUMENT_ROOT']
, which returns the absolute path to the web root directory. This is by far the best (and most portable) solution. The following example shows the environment variable in action.
Example Include
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>
I had the same error while including file from root of my project in codeigniter
.I was using this in common.php
of my project.
<?php include_once base_url().'csrf-magic-master/csrf-magic.php'; ?>
i changed it to
<?php include_once ('csrf-magic-master/csrf-magic.php'); ?>
Working fine now.
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 using esc
then press /include_path
then enter
include_path = ".:/usr/share/php:/var/www/<directory>/"
sudo service apache2 restart
This is it. Hope it helps.
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.
Actually, the solutions is to open the php.ini file edit the include_path line and either completely change it to
include_path='.:/usr/share/php:/usr/share/pear'
or append the
'.:/usr/share/php:/usr/share/pear'
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
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...
require_once ( 'db/config.php');