PHP IIS 7 and FastCGI not working - php

I've followed the directions here: Using FastCGI to Host PHP Applications on IIS 7 to configure Windows 2008, PHP with IIS 7 and FastCGI, and I'm running into issues. The PHP version is 5.3.8. I've setup the Handler Mappings on IIS, and created a test page, though the page doesn't return anything except for a 500 error. I've ensured that PHP works, from the command line I get a response when I enter:
php -version.
That said, I've turned on Failed Request Tracing Rules for php pages, and when I browse through the error log, I see things like:
<EventData>
<Data Name="ContextId">{00000000-0000-0000-0200-0080010000F6}</Data>
<Data Name="ModuleName">FastCgiModule</Data>
<Data Name="Data1">FASTCGI_RESPONSE_ERROR</Data>
<Data Name="Data2">PHP Warning: phpinfo() [<a href=&apos;function.phpinfo&apos;>function.phpinfo</a>]: It is not safe to rely on the system&apos;s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected &apos;America/New_York&apos; for &apos;-4.0/DST&apos; instead in C:\inetpub\wwwroot\phpinfo.php on line 1
</Data>
<Data Name="ErrorCode">5</Data>
</EventData>
<RenderingInfo Culture="en-US">
<Opcode>MODULE_WARNING</Opcode>
<Keywords>
<Keyword>Module</Keyword>
</Keywords>
<freb:Description Data="ErrorCode">Access is denied.
(0x5)</freb:Description>
From the top of the failed request log, I can see it's running under IUSR account:
tokenUserName="NT AUTHORITY\IUSR"
Here's settings for the fastCgi:
<fastCgi>
<application fullPath="C:\PHP\php-cgi.exe" instanceMaxRequests="10000">
<environmentVariables>
<environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
<environmentVariable name="PHPRC" value="C:\php\php.ini" />
</environmentVariables>
</application>
</fastCgi>
<handlers accessPolicy="Read, Script">
<add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe" resourceType="Unspecified" requireAccess="Script" />
I've ensure that this user name has full control over my C:\PHP directory. My php.ini file is configured within C:\PHP directory.
In addition to following the directions in that article, I also tried to create a script map for PHP, and when I created that I got a difference error, not a 500.
HTTP Error 403.1 - Forbidden
You have attempted to run a CGI, ISAPI, or other executable program from a directory that does not allow executables to run.
Once again though, IUSR has full control over that directory so I don't quite understand why that error message.
Update
The issue was glaring right at me in the log. I had ignored the PHP Warning with regard to the date.timezone thinking that it's just a warning. I set it to:
date.timezone = America/New_York
and now it works.

For future reference you can use http://php.iis.net/ to easily install php into your IIS setup. It comes with a manager which will also let you go into 'development mode' which will display php errors as opposed to covering them up.

Related

Apache with PHP: Can't find module?

trying to use LoadFile "C:/ProgramFiles/PostgreSQL/15/bin/libpq.dll" in the httpd.conf file.
I keep getting this from the error logs:
Log Name: Application
Source: Apache Service
Date: 1/24/2023 6:46:09 PM
Event ID: 3299
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: Cedric-PC
Description:
The Apache service named reported the following error:
>>> httpd.exe: Syntax error on line 542 of C:/Apache24/conf/httpd.conf: Cannot load C:/ProgramFiles/PostgreSQL/15/bin/libpq.dll into server: The specified module could not be found. .
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Apache Service" />
<EventID Qualifiers="0">3299</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2023-01-24T23:46:09.4847737Z" />
<EventRecordID>52674</EventRecordID>
<Correlation />
<Execution ProcessID="0" ThreadID="0" />
<Channel>Application</Channel>
<Computer>Cedric-PC</Computer>
<Security />
</System>
<EventData>
<Data>The Apache service named</Data>
<Data>
</Data>
<Data>reported the following error:
>>></Data>
<Data>httpd.exe: Syntax error on line 542 of C:/Apache24/conf/httpd.conf: Cannot load C:/ProgramFiles/PostgreSQL/15/bin/libpq.dll into server: The specified module could not be found.</Data>
<Data>
</Data>
<Data>
</Data>
<Data>
</Data>
<Data>
</Data>
<Data>
</Data>
</EventData>
</Event>
Everything is running x64. Apache is on VC15. PostgreSQL is 15.
I have no idea how to troubleshoot this.
EDIT:
Syntax error. Needed a space between "Program Files"...
There are a couple things I noticed with the information you have provided.
Firstly, "C:/ProgramFiles/" is not a valid directory path.
It is typically "C:/Program Files/" or "C:/Program Files (x86)/"
I recommend copy/paste the folder path from the Windows explorer directory when you need to specify an absolute path like this.
Second, with Apache, you cannot load any arbitrary DLL file.
It must be a compiled library that is built for Apache, typically "mod_" will always be in it's name.
Finally,
Since the tag php is part of your post, I will assume that is what your web application is written in.
Normally, you would load an extension within php, in the php.ini file.
Look for your php.ini file within the installation directory.
Find the lines
extension=php_pgsql.dll
extension=php_pdo_pgsql.dll
Uncomment one, or both of them. Which ever fits your needs.
You may need to direct your PATH environment variable to the location where libpq.dll is located to have php find it.
I have worked in IT my entire life, and have been using Apache and php for most of that time.
Best of luck.

PHP / IIS does not interpret php code correctly -> blank page for phpinfo()

on my Win 10 machine i would like to use PHP on IIS. I went through different tutorials to get it to work but currently when i call the index.php file i got an blank page and the response is only the content of the php file (see this in browser dev tools).
content of the file:
`
<?php
phpinfo();
?>
`
Result
what i have done is:
installed CGI under Windows features
php 8.1.2 x86 Non thread safe unzipped under C:\php
php.ini adjusted like described in the tutorial(s)
linked the directory under environment variables to C:\php
set the handler mapping for php in IIS
checked the fast cgi module in IIS
I also activated the Failed Requested Trace in IIS and the outcoming log had following section:
For me it looks good, or i am wrong? If its helpful i can post the whole .xml, but it is very large.
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="WWW Server" Guid="{3A2A4E84-4C21-4981-AE10-3FDA0D9B0F83}"/>
<EventID>0</EventID>
<Version>1</Version>
<Level>4</Level>
<Opcode>43</Opcode>
<Keywords>0x0</Keywords>
<TimeCreated SystemTime="2022-11-15T15:58:47.038Z"/>
<Correlation ActivityID="{8000000A-0005-FF00-B63F-84710C7967BB}"/>
<Execution ProcessID="5540" ThreadID="1392"/>
<Computer>SRV01</Computer>
</System>
<EventData>
<Data Name="ContextId">{8000000A-0005-FF00-B63F-84710C7967BB}</Data>
<Data Name="OldHandlerName"></Data>
<Data Name="NewHandlerName">PHP_via_FastCGI</Data>
<Data Name="NewHandlerModules">FastCgiModule</Data>
<Data Name="NewHandlerScriptProcessor">C:\php\php-cgi.exe</Data>
<Data Name="NewHandlerType"></Data>
</EventData>
<RenderingInfo Culture="de-DE">
<Opcode>HANDLER_CHANGED</Opcode>
</RenderingInfo>
<ExtendedTracingInfo xmlns="http://schemas.microsoft.com/win/2004/08/events/trace">
<EventGuid>{D42CF7EF-DE92-473E-8B6C-621EA663113A}</EventGuid>
</ExtendedTracingInfo>
</Event>

FastCGI error after PHP Upgrade

As outlined in a previous question (https://stackoverflow.com/questions/21648349/php-5-5-9-test-failures-and-internal-server-errors) my server administrator recently tried to install php 5.5.9 (using a wrapper) alongside our current configuration, which is php 5.3.8. The o/s is Opensuse 12.1, and it's a Plesk server (11.0.9).
After a successfull installation and initiating the new configuration on a specific vhost, every php script throws out a 500 Internal Server Error. The Apache logs do not show any useful information, however we were able to get mod_sec to pickup a fastcgi error which is as follows:
**Apache-Error:
[file "fcgid_proc_unix.c"] [line 634] [level 4] [status 104] mod_fcgid: error reading data from FastCGI server
Apache-Error: [file "util_script.c"] [line 435] [level 19] Premature end of script headers: db.php**
This error appears only when 5.5.9 is active, and disappears as soon as we switch back to 5.3.8. This is the only lead we have to go on :(
We've also tried checking htaccess & permissions, so far no change.
Thanks!
Problem solved, finally.
In our case we had to CHMOD the cgi-bin for the vhost to 755 (it was 775). After that, smooth running!

Tsung load test from mac os x

I am trying to fire off a Tsung request from my Mac OS X machine and i'm not having much luck.
I have edited the ~/.tsung/tsung.xml config file and even tried changing the location of that file on several occasions with the -f parameter.
When I run tsung start it returns this output
dave:/Applications/MAMP/htdocs/barebonessite/wp-content/themes/barebones $ tsung -f ~/.tsung/tsung.xml -l . start
Starting Tsung
"Log directory is: /Applications/MAMP/htdocs/barebonessite/wp- content/themes/barebones/./20130503-1325"
Config Error, aborting ! {{case_clause,{error,enoent}},
[{xmerl_scan,fetch_DTD,2,
[{file,"xmerl_scan.erl"},{line,1283}]},
{xmerl_scan,scan_doctype2,3,
[{file,"xmerl_scan.erl"},{line,1227}]},
{xmerl_scan,scan_prolog,4,
[{file,"xmerl_scan.erl"},{line,722}]},
{xmerl_scan,scan_document,2,
[{file,"xmerl_scan.erl"},{line,563}]},
{xmerl_scan,file,2,
[{file,"xmerl_scan.erl"},{line,249}]},
{ts_config,read,2,
[{file,"src/tsung_controller/ts_config.erl"},
{line,68}]},
{ts_config_server,handle_call,3,
[{file,
"src/tsung_controller/ts_config_server.erl"},
{line,198}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,588}]}]}
My config file looks like this:
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
<clients>
<client host='localhost' use_controller_vm='true'/>
</clients>
<servers>
<server host="54.225.212.193" port="80" type="tcp"></server
</servers>
<load>
<arrivalphase phase="1" duration="10" unit="minute">
<users maxnumber="650" arrivalrate="8" unit="second"/>
</arrivalphase>
</load>
<sessions>
<session probability="100" name="ab" type="ts_http">
<for from="1" to="20" var="i">
<request> <http url="/" method="GET" version="1.1"/> </request>
</for>
</session>
</sessions>
</tsung>
Being new to Tsung I cannot work out the problem here and the error reporting is pretty low level stuff and makes little sense.
I used Homebrew to install tsung on osx and was getting this error when using the example xml files.
Config Error, aborting ! dtd_not_found
Replacing the doc type line with this fixed it:
<!DOCTYPE tsung SYSTEM "/usr/local/Cellar/tsung/1.6.0/share/tsung/tsung-1.0.dtd">
This error is related to a dtd file missing, could you check that the file /usr/share/tsung/tsung-1.0.dtd exists, it seems not.
Secondly your xml file seems to contains a syntax error on a non close tag
Regards
There might be another path in case you are using some other Linux distributions (not mac os):
/usr/local/share/tsung/tsung-1.0.dtd
note local part

PHP Extension (memcache|memcached) not showing in phpinfo() but showing in php -m and php -i?

I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.

Categories