Newbie: MySql is loaded when PHP runs from command line, but not through IIS

Newbie: MySql is loaded when PHP runs from command line, but not through IIS

am 21.08.2007 12:01:20 von Alan Silver

Hello,

Sorry for the newbie question, but I've been searching and searching and
haven't found an answer to this one yet.

I installed PHP and MySql (both latest versions) yesterday on a machine
running Windows 2003 Server with IIS6. I followed the instructions at:

http://www.tjitjing.com/blog//2006/05/php5-with-iis6-on-wind ows-server-2003.html

to install PHP, and all seemed to go fine. I can run PHP pages through
IIS. Installation of MySql also went OK, and that seems to be running. I
can use the command line to create databases, create users, run select
statements, etc.

I then configured PHP to be able to use MySql. I uncommented the two
extension line in php.ini, and set the extension_dir to be the folder
where the DLLs live. This is where things started to go wrong ;-)

If I open a command prompt and run php_info(), then MySql is shown as a
loaded extension. I can use mysql_connect() and it will open a
connection to MySql fine.

However, if I run php_info() from a page loaded under IIS, then MySql is
NOT shown as loaded. If I try to use mysql_connect(), then I get an
error telling me that mysql_connect() is undefined - presumably because
IIS does not think the extension is loaded.

I have stopped and restarted IIS, and even rebooted the machine, but it
didn't make any difference. When called from IIS, PHP doesn't think that
MySql is loaded, even though it works fine when run from a command line.

All required DLLs are present, and the extension folder is referenced
both in the php.ini file and in the system PATH variable. The fact that
it works from a command line confirms that this is OK.

Any ideas? I have been searching for ages, but not found an answer to
this one. TIA for any help you can give.

--
Alan Silver
(anything added below this line is nothing to do with me)

Re: Newbie: MySql is loaded when PHP runs from command line, but not through IIS

am 21.08.2007 12:48:25 von Alan Silver

In article , Alan Silver
writes
>Hello,

Quick follow-up to my question...

I noticed that the phpinfo() shows you the path that PHP uses to look
for the php.ini file. This currently shows as C:\Windows, which is where
php.ini lives, but when run from IIS, the next line down says:

Loaded Configuration File (none)

....which looks like it is the problem. If IIS isn't loading php.ini when
it runs PHP, then it will use the default configuration, which doesn't
load the MySql extension.

When I run phpinfo() from a command line, the configuration file is
loaded OK, which is presumably why PHP can connect to MySql from command
line scripts.

So, I think I've found the problem, but I'm not sure how to fix it.

TIA again for any help

--
Alan Silver
(anything added below this line is nothing to do with me)

Re: Newbie: MySql is loaded when PHP runs from command line, but not through IIS

am 21.08.2007 13:02:52 von Alan Silver

In article , Alan Silver
writes
>>Hello,
>
>Quick follow-up to my question...

And again! I found that I need to set the PHPRC environment variable to
C:\Windows and restart IIS. After that it worked fine.

Thanks a lot to me for all the help I gave me ;-)

--
Alan Silver
(anything added below this line is nothing to do with me)

Re: Newbie: MySql is loaded when PHP runs from command line, butnot through IIS

am 21.08.2007 13:06:23 von Jerry Stuckle

Alan Silver wrote:
> In article , Alan Silver
> writes
>> Hello,
>
> Quick follow-up to my question...
>
> I noticed that the phpinfo() shows you the path that PHP uses to look
> for the php.ini file. This currently shows as C:\Windows, which is where
> php.ini lives, but when run from IIS, the next line down says:
>
> Loaded Configuration File (none)
>
> ...which looks like it is the problem. If IIS isn't loading php.ini when
> it runs PHP, then it will use the default configuration, which doesn't
> load the MySql extension.
>
> When I run phpinfo() from a command line, the configuration file is
> loaded OK, which is presumably why PHP can connect to MySql from command
> line scripts.
>
> So, I think I've found the problem, but I'm not sure how to fix it.
>
> TIA again for any help
>

It should be loaded as long as C:\Windows is in your path. Is that the
case?

The reason I ask - C:\Windows is not necessarily the default path for a
Windows installation. And if it isn't on your system, that could be
your problem.

If it is in your path, does the IIS user have permission to access the file?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Newbie: MySql is loaded when PHP runs from command line, but not through IIS

am 21.08.2007 13:26:35 von Alan Silver

In article , Jerry Stuckle
writes
>Alan Silver wrote:
>> In article , Alan Silver
>> writes
>>> Hello,
>> Quick follow-up to my question...
>> I noticed that the phpinfo() shows you the path that PHP uses to
>>look for the php.ini file. This currently shows as C:\Windows, which
>>is where php.ini lives, but when run from IIS, the next line down says:
>> Loaded Configuration File (none)
>> ...which looks like it is the problem. If IIS isn't loading php.ini
>>when it runs PHP, then it will use the default configuration, which
>>doesn't load the MySql extension.
>> When I run phpinfo() from a command line, the configuration file is
>>loaded OK, which is presumably why PHP can connect to MySql from
>>command line scripts.
>> So, I think I've found the problem, but I'm not sure how to fix it.
>> TIA again for any help
>>
>
>It should be loaded as long as C:\Windows is in your path. Is that the
>case?

Yup, it's the first entry in the PATH variable.

>The reason I ask - C:\Windows is not necessarily the default path for a
>Windows installation. And if it isn't on your system, that could be
>your problem.

Good point, but not the case here.

>If it is in your path, does the IIS user have permission to access the file?

Not sure, but as I mentioned in my second reply to myself (which you
probably hadn't see when you posted), it turned out that I needed to set
the PHPRC variable to get the config file loaded under IIS. As that
fixed it, I guess IIS had the right permissions!

Thanks for the reply

--
Alan Silver
(anything added below this line is nothing to do with me)

Re: Newbie: MySql is loaded when PHP runs from command line, butnot through IIS

am 21.08.2007 14:21:42 von Jerry Stuckle

Alan Silver wrote:
> In article , Jerry Stuckle
> writes
>> Alan Silver wrote:
>>> In article , Alan Silver
>>> writes
>>>> Hello,
>>> Quick follow-up to my question...
>>> I noticed that the phpinfo() shows you the path that PHP uses to
>>> look for the php.ini file. This currently shows as C:\Windows, which
>>> is where php.ini lives, but when run from IIS, the next line down says:
>>> Loaded Configuration File (none)
>>> ...which looks like it is the problem. If IIS isn't loading php.ini
>>> when it runs PHP, then it will use the default configuration, which
>>> doesn't load the MySql extension.
>>> When I run phpinfo() from a command line, the configuration file is
>>> loaded OK, which is presumably why PHP can connect to MySql from
>>> command line scripts.
>>> So, I think I've found the problem, but I'm not sure how to fix it.
>>> TIA again for any help
>>>
>>
>> It should be loaded as long as C:\Windows is in your path. Is that
>> the case?
>
> Yup, it's the first entry in the PATH variable.
>
>> The reason I ask - C:\Windows is not necessarily the default path for
>> a Windows installation. And if it isn't on your system, that could be
>> your problem.
>
> Good point, but not the case here.
>
>> If it is in your path, does the IIS user have permission to access the
>> file?
>
> Not sure, but as I mentioned in my second reply to myself (which you
> probably hadn't see when you posted), it turned out that I needed to set
> the PHPRC variable to get the config file loaded under IIS. As that
> fixed it, I guess IIS had the right permissions!
>
> Thanks for the reply
>

Nope, it hadn't made it to my server yet.

Glad you got it working, but I'm not sure why you had to set it. I
didn't on the Windows systems I have.

But as long as it's working, that's what counts.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================