Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot use relative paths in PHP scripts

Status
Not open for further replies.

GrazBurya

Technical User
Jul 19, 2007
5
US
I am running Fedore Core 6 and recently I upgraded PHP and Pear. Before the upgrade, include_path was not used and most of my scripts used relative paths. After the upgrade, I am getting 'file not found' errors in my error_log and blank pages on my sites for all my scripts that have require("relative/path/to/file"). include_path is still not set in /etc/php.ini but phpinfo() shows include_path=".:/usr/share/pear". Two solutions I've found are to change my require statements to require("/absolute/path/to/file") or append /path/to/working/dir to include_path. Both of these solutions are time consuming bcos I have a couple hundred scripts and they do not all reside in the same directory. I don't which file is setting include_path and I would very muc like to disable it. Any help will be greatly appreciated. Thanks.
 
it sounds like the location of your php.ini file has changed. phpinfo should report the current location of the ini file being used. just find the right one, and edit it to include whatever directories you need. If it currently includes the dot (cwd) as you say, then relative paths should work "out of the box". Certainly the setting of an include path will not be the cause of your problem.

if none of the above works you possible have a duff implementation of php and need to recompile it.

as a workaround you can also do the following at the top of each script

Code:
set_include_path(".:/usr/share/pear");

assuming that pear is, indeeed, located in /usr/share/pear. for explicitly seting the current *working* directory, add the following

Code:
$cwd = (getcwd()===false) ? '' : getcwd();
set_include_path(".:/usr/share/pear:$cwd");

 
Hey guys, thanks for your response.
phpinfo() shows the location of my php.ini as /etc/php.ini...After some searching, I found the following files /usr/share/pear/pearcmd.php and /usr/share/pear/peclcmd.php that both has a ini_set('include_path', '/usr/share/pear'); in them...I've commented out these lines and restarted the web service but my include_path is still showing as include_path=".:/usr/share/pear". Adding set_include_path(".:/usr/share/pear"); at the top my script did not work, it produced the same error in my error_log. Adding
Code:
$cwd = (getcwd()===false) ? '' : getcwd();
set_include_path(".:/usr/share/pear:$cwd");
I think will work but will be the same as adding all the directories to include_path in /etc/php.ini which I am trying to avoid. The thing is, when include_path was not set, I had no problems with my relative paths...Now it's been set and I am trying to figure out how to unset it but I don't know which file is setting it.
 
i still don't see why relative paths are troubled by anything in your include path. i suspect something else is at work.
 
Over the weekend I installed a new System running Windows XP, Apache 2.2.2, PHP 5.2.3 and out the the box I am getting the same problem. I cannot use relative paths and include_path=.;C:\PHP5\pear is being set outside of C:\Windows\php.ini...On another box, I have Fedora 4, PHP 4, Apache 2.0.58 and I copied the exact same scipt over there and it runs without errors. On this box include path is not set. On the others, include_path is commented out in either /etc/php.ini for Linux and C:\Windows\php.ini for Windows. Also, running phpinfo() on either shows the correct location of php.ini but still shows an include_path. Is there like an ini_unset or something to disable include_path? I use dynamic virtual hosting so it's much easier to use paths relative to each domain.
 
Doing some testing on my setup Windows XP/Apache 2.2/PHP 5.2.3

The include_path directive is commented out by default, and loading up the phpinfo() file shows:
Code:
include_path .;C:\php5\pear
So I have to assume if PHP finds no include_path directive it defaults to this.

If you uncomment the include_path directive and leave it blank it also defaults to what is shown above.

From these tests I assume there is no way to actually turn off the include_path directive.

I do agree with:
jpadie said:
If it currently includes the dot (cwd) as you say, then relative paths should work "out of the box". Certainly the setting of an include path will not be the cause of your problem.
My normal setup is to leave the include_path commented out in the php.ini file, which means it is set to '.;C:\php5\pear' and I use relative paths without a problem.


-- -- -- -- -- -- -- --

If you give someone a program, you will frustrate them for a day
but if you teach them how to program, you will frustrate them for a lifetime.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top