Page 1 of 1

php.ini, IIS and Include_Path

Posted: Wed Mar 06, 2013 6:03 pm
by tmac25
So, I recently was given a new server to work with, the only conditions were that it had to be Windows 2012 (64-bit), IIS8 and MSSQL. (I originally asked for a LAMP stack, oh well.)

All was going well until when I moved my old LAMP include folder to where I usually put it, just outside the webroot, and now all my includes aren't working.

php.ini - verified it is set by a echo ini_get('include_path'); & phpinfo();

Code: Select all

include_path = ".;c:\inetpub\inc"
Inside that folder is test.php, which has this code:

Code: Select all

<?php

echo "Hello!";

?>
And in the index of the webroot I have:

Code: Select all

<?php

include('test.php');

?>
file_exists can't even find it.

In Apache this would include the test.php from "c:\inetpub\inc" and echo "Hello!" on the page, under IIS it does not. Any ideas? I've spent a good portion of my day Googling this issue.

Everything else is working better than I was expecting.

Re: php.ini, IIS and Include_Path

Posted: Wed Mar 06, 2013 6:51 pm
by requinix
So you get the error about file not found which mentions the include_path in the message?

Re: php.ini, IIS and Include_Path

Posted: Wed Mar 06, 2013 6:54 pm
by tmac25
I'm sorry, what I meant was that file_exists appears to not be able to see outside of the web root.

EDIT: Now, that I actually type that out, could this be a file permission issue with php and the win server?

Ya, file_exists can see everything inside of c:\inetpub\wwwroot but not anything outside of that, I don't want to allow everyone read access to outside the webroot, but I also don't want to store my db include in the webroot, hmm.

Re: php.ini, IIS and Include_Path

Posted: Wed Mar 06, 2013 7:49 pm
by Doug G
Now, that I actually type that out, could this be a file permission issue with php and the win server?
Sure. Make sure the IIS user account has permission in the c:\inetpub\inc\ dirrectory.

Also, I haven't used php on IIS since W2003, but it seems to me I had to fiddle around a lot with the syntax for the php include path setting. Also, just a tip run phpinfo() and make sure you're editing the active php.ini file. Windows servers seem to often end up with multiple php.ini files but only one active one.

Re: php.ini, IIS and Include_Path

Posted: Wed Mar 06, 2013 8:13 pm
by tmac25
Doug G wrote:
Now, that I actually type that out, could this be a file permission issue with php and the win server?
Sure. Make sure the IIS user account has permission in the c:\inetpub\inc\ dirrectory.

Also, I haven't used php on IIS since W2003, but it seems to me I had to fiddle around a lot with the syntax for the php include path setting. Also, just a tip run phpinfo() and make sure you're editing the active php.ini file. Windows servers seem to often end up with multiple php.ini files but only one active one.
Thank you Doug, I added the IIS user account to the entire IIS directory, but for some reason my php still cannot see outside of the web root

EDIT: Oh, and trust me when I said I've been Googling for a while, I have, the multiple php.ini came up, A LOT. :) I am editing the correct loaded php.ini.

This sample test code should help explain what I mean.

Code: Select all

$filename="C:\inetpub\wwwroot\index.php";
If(!file_exists($filename)){
    echo "No file was found..."; 
}
else{
    echo "FOUND IT!"; // this is what is returned.

Code: Select all

$filename="C:\inetpub\inc\functions.inc.php";
If(!file_exists($filename)){
    echo "No file was found..."; // this is what is returned.
}
else{
    echo "FOUND IT!";

Re: php.ini, IIS and Include_Path

Posted: Wed Mar 06, 2013 8:21 pm
by requinix
Are you using double " quotes in your test? Because that's a problem: that \f you have tucked in there is a form feed character. Try with single ' quotes.

Re: php.ini, IIS and Include_Path

Posted: Wed Mar 06, 2013 9:02 pm
by tmac25
Bah, you're right. Such a rookie mistake. I knew that one too. :P

Corrected:

Code: Select all

<?php
echo ini_get('include_path');
include('test.php');

$filename='C:\inetpub\inc\functions.inc.php';
If(!file_exists($filename)){
    echo "what file?"; // still getting this.
}
else{
    echo "FOUND IT!";
}
$filename='C:\inetpub\wwwroot\index.php';
If(!file_exists($filename)){
    echo "what file?";
}
else{
    echo "FOUND IT!"; // still getting this.
}
?>
Edit: Still doesn't work. :(

Re: php.ini, IIS and Include_Path

Posted: Thu Mar 07, 2013 6:50 am
by tmac25
Alright, it was a Windows permissions issue, kinda embarrassing I didn't try this originally, but I am a linux/Apache guy, but at least I know more about IIS and Windows now. :) If anyone ever runs into this issue, For Windows 2012, if you want includes to work, you have to right click the folder, Properties, Security, and give Everyone read access to the folder.

Thanks