Forum Moderators: coopster
As soon as I got my new PHP install set-up, most everything worked, but any script that referenced another file, by an include() or require() for instance, failed with an error "No such file or directory".
The references are relative... i.e.
include("include/script.php");orinclude("../include/script.php"); I do them relative because the site runs locally on a subdir, not the domain root like the live server, and also - well, because there's no reason not to. Damned if I'm going to hard-code absolute paths.
include_path does have '.' added. However include_path is not the problem, as below.
I have hacked the include()s to work by explicitly adding the local root dir of the site to the include_path in php.ini. This is a BS fix in my opinion, and I want to know why the code doesn't work just as it should (and does on other servers).
Furthermore, even with the include_path fudged, there is another error from a fopen() call, also referencing a relative path, which fails with the same error. I am unable to hack this, as obviously the include_path does not apply! So I'm stumped.
Any ideas?
Isn't this where your problem lies. You are keeping the scripts in two different locations with the same paths to the files. For your live site you might be going below the webroot to grab the include files, as with the local server you are going into the root directory.
For portability purposes, I could have a config file prepended to a script like this. Maybe it would look like the following:
if(stristr($_SERVER['HTTP_HOST'], 'local') ¦¦ (substr($_SERVER['HTTP_HOST'], 0, 7) == '192.168')) {
# local server
ini_set('include_path', '/dir/includes');
} else {
# live server
ini_set('include_path', '/includes');
}
or something along those lines. This way, you don't have to use anything more than just:
include('script.php');
(The only calls are in sub-dirs from the root. It never goes below the root then back out. See examples above.)
Therefore, I am unwilling to make any changes to the site. I appreciate your code is a quick fix (although, I think like include_path in php.ini it also will NOT fix the real problem which is with fopen()...!). Because it works fine on other servers, it has to be a config thing... which is why I'm looking for such a solution.
Like npwsol's suggestion - although I'm afraid I can't find anything like "enable parent paths" in IIS7. Not even scripts configuration LOL. Nothing in its help either.
So this is an issue with the application virtual path set-up. I have just wasted hours on Google and can't find any solutions. A few other sites that don't use relative paths work fine, also in virtual directories, so it's something to do with what IIS is showing PHP...
Note that above /site is still in a subdirectory, just it's real path is below wwwroot instead of a virtual path referencing another location. So the above discussion was a bit of a red herring. PHP and the script is working A-OK...
So any more ideas?
I have just made a new thread over in the IIS forum, so maybe this should direct there now.
[webmasterworld.com...]
I set up Apache and an FTP server for development here, and if I FTP stuff into the www folder under Apache, it does not appear there.
It gets dumped to C:/blah/blah/Application Data/Apache/blah/blah/ or somesuch, as Vista will not me put user data into a folder that is seen as being an application.
.
I also met a similar problem to yours, with PHP, with my development vs. real server. In the end I specify the PHP Include path using this php_value include_path in the .htaccess file for the site. I leave both lines in there and comment one out, depending on where the file is destined for. That's also not ideal, but it works for me.
BUT includes still fail.
The site works PERFECTLY in a subdir... i.e. if it locally located in wwwroot/site, then localhost/site accesses it just fine. But if it's an application [virtual dir] called 'site', then localhost/site fails with 'no such file' errors.
Anyone got any ideas?
After wasting several hours, trying to debug my app, I decided to try to check the current working directory of the php script in app root folder. I used the code sample from php manual (see dir()), then executed this peace of code from my app root folder. It gave out the list of files (exe, dlls...) from some windows/system32 subfolder (apparently IIS files in it). When I tried to put this script into the wwwroot folder and execute it, I got the expected list of files in the wwwroot. It was clear, that relative paths didn't work due to the different working directories.
I've made comparison of my app and wwwroot folder NTFS permissions and it turned out, that wwwroot had Users group assigned with read&execute and list folder permissions. My app root folder lacked this group. After giving the same permissions for Users group to my app root folder, relative paths started to work.
Don't know why, but apparently IIS7 needs this group assigned, to have set the proper working directory of the script. Anyway, my suggestion is to verify that Users group is assigned to your app folder with read, execute and list files permissions set.
I believe I ensured permissions were identical on both locations before. For the time being I've given up, and am just running the site under wwwroot. I cannot believe that IIS7 is this bad, this difficult to set up for a simple PHP site! It's quite incredible.
I might see what dir() tells me.
I had a phpBB installation in "/wwwroot/phpBB/", with the user with read and execute permissions given permissions to directory. The pages in the/phpBB/admin/ directory worked correctly, but the pages in the root didn't. Giving the phpBB user read permissions to the /wwwroot/ directory fixed the problem.