Cacti/PHP Problem Under Windows

Post support questions that relate to the Windows 2003/2000/XP operating systems.

Moderators: Developers, Moderators

raX
Lead Developer
Posts: 2243
Joined: Sat Oct 13, 2001 7:00 pm
Location: Carlisle, PA
Contact:

Cacti/PHP Problem Under Windows

Post by raX »

There is currently a problem with PHP under Windows that causes Cacti to 'block' the web server when viewing graphs. The problem only manifests under certain conditions that are all met when Cacti is generating graphs. I have successfully reproduced it under both Apache (1|2) and IIS (5|6). This bug has been reported to PHP, but so far nothing has been done about it.

If you want to help out, comment or vote on this bug. I would love to see this get fixed ASAP, as it still appears broken in 4.3.2-win32.

http://bugs.php.net/bug.php?id=22526

Currently the only workaround seems to be to set Apache/IIS to CGI mode for PHP. Of course this is less than optimal and should not be necessary to get Cacti running.

-Ian
Last edited by raX on Sat Apr 10, 2004 1:40 pm, edited 1 time in total.
Guest

Post by Guest »

How do I set IIS to use cgi mode ??
Systimax
Posts: 3
Joined: Wed May 28, 2003 6:46 am
Location: PARIS (FRANCE)

About CLI/CGI mode on IIS and Apache

Post by Systimax »

Guys,

I aggre with you but can you write a Turn around procedure or saying how to find info about how apply CLI/CGI mode for PHP.

Regards.

Patrice
Guest

Post by Guest »

found it :

Windows NT/2000/XP and IIS 4 or newer and PWS 4 on NT Workstation or W2K non server editions

To install PHP on an NT/2000/XP Server running IIS 4 or newer,
follow these instructions. You have two options to set up
PHP, using the CGI binary (php.exe) or with the ISAPI module.

In either case, you need to start the Microsoft Management
Console (may appear as 'Internet Services Manager', either
in your Windows NT 4.0 Option Pack branch or the Control
Panel=>Administrative Tools under Windows 2000). Then
right click on your Web server node (this will most probably
appear as 'Default Web Server'), and select 'Properties'.

If you want to use the CGI binary, do the following:
Under 'Home Directory', 'Virtual Directory', or
'Directory', click on the 'Configuration' button,
and then enter the App Mappings tab.

Click Add, and in the Executable box, type:
c:\php\sapi\php.exe (assuming that you have unzipped PHP in c:\php\).

Please note that you cannot use php-cli.exe with your webserver, you need
to use php.exe which can be found in the sapi directory of your PHP
distribution.

In the Extension box, type the file name extension you want
associated with PHP scripts. Leave 'Method exclusions'
blank, and check the Script engine checkbox. You may also
like to check the 'check that file exists' box - for a small
performance penalty, IIS (or PWS) will check that the script
file exists and sort out authentication before firing up php.
This means that you will get sensible 404 style error messages
instead of cgi errors complaing that php did not output any data.

You must repeat from 'Click Add...' for each extension you
want associated with PHP scripts.
(.php is recommended. although .phtml and .php3 may be
required for legacy applications.)

Set up the appropriate security. (This is done in Internet
Service Manager), and if your NT Server uses NTFS file system,
add execute rights for I_USR_ to the directory that contains
php.exe

To use the ISAPI module, do the following:

If you don't want to perform HTTP Authentication using PHP,
you can (and should) skip this step. Under ISAPI Filters,
add a new ISAPI filter. Use PHP as the filter name, and
supply a path to the php4isapi.dll.

Under 'Home Directory', click on the 'Configuration' button.
Add a new entry to the Application Mappings. Use the path
to the php4isapi.dll as the Executable, supply .php as the
extension, leave Method exclusions blank, and check the
Script engine checkbox.

Stop IIS completely (net stop iisadmin)
Start IIS again (net start w3svc)

----------------------------------------------------------
Systimax
Posts: 3
Joined: Wed May 28, 2003 6:46 am
Location: PARIS (FRANCE)

Post by Systimax »

Guys,

I look at it and follow exactly install notes coming with PHP product and everything working fine now.

So you will fine under wht's to be done to make PHP runing CGI mode for all Windows platform using IIS/WS (find notes for Apache Server at the end of this document):

Installing PHP on Windows with IIS/PWS

This section contains notes and hints specific to IIS (Microsoft
Internet Information Server). Installing PHP for PWS/IIS 3 and
PWS/IIS 4 or newer versions.

Windows and PWS/IIS 3 - including PWS on Win 9x/ME

The recommended method for configuring these servers is to use
the REG file incuded with the distribution (pws-php4cgi.reg).
You may want to edit this file and make sure the extensions and PHP
install directories match your configuration - once you have done
this, just double click on the file and it will update your registry.
Alternatively, you can follow the steps below to do it manually.

WARNING:
These steps involve working directly with the Windows
registry. One error here can leave your system in an unstable
state. We highly recommend that you back up your registry
first. The PHP Development team will not be held responsible if
you damage your registry.

Run Regedit.
Navigate to:
HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/W3Svc/Parameters/ScriptMap
On the edit menu select: New->String Value.
Type in the extension you wish to use for your php scripts. ex: .php
Double click on the new string value and enter the path to
php.exe in the value data field.
ex: c:\php\php.exe
Repeat these steps for each extension you wish to associate
with PHP scripts.

The following steps do not affect the web server installation and only
apply if you want your php scripts to be executed when they are run
from the command line (ex. run c:\myscripts\test.php) or by double
clicking on them in a directory viewer window. You may wish to skip
this step as you might prefer the php files to load into a text
editor when you double click on them.

Now navigate to: HKEY_CLASSES_ROOT
On the edit menu select: New->Key
Name the key to the extension you setup in the previous
section. ex: .php
Highlight the new key and in the right side pane, double click
the "default value" and enter phpfile.
Repeat the last step for each extension you set up in the
previous section.
Now create another New->Key under
HKEY_CLASSES_ROOT and name it phpfile
Highlight the new key 'phpfile' and in the
right side pane, double click the "default value" and enter
PHP Script.
Right click on the 'phpfile' key and select
New->Key, name it Shell.
Right click on the 'Shell' key and select
New->Key, name it open.
Right click on the 'open' key and select
New->Key, name it command.
Highlight the new key 'command' and in the
right side pane, double click the "default value" and enter
the path to php.exe ex: c:\php\php.exe -q %1
(don't forget the '%1').
Exit Regedit.
If using PWS on Windows, reboot to reload the registry.
PWS and IIS 3 users now have a fully operational system. IIS 3
users can use a nifty tool available at
http://www.genusa.com/iis/iiscfg.html
from Steven Genusa to configure their script maps.

Windows NT/2000/XP and IIS 4 or newer and PWS 4 on NT Workstation or W2K non server editions

To install PHP on an NT/2000/XP Server running IIS 4 or newer,
follow these instructions. You have two options to set up
PHP, using the CGI binary (php.exe) or with the ISAPI module.

In either case, you need to start the Microsoft Management
Console (may appear as 'Internet Services Manager', either
in your Windows NT 4.0 Option Pack branch or the Control
Panel=>Administrative Tools under Windows 2000). Then
right click on your Web server node (this will most probably
appear as 'Default Web Server'), and select 'Properties'.

If you want to use the CGI binary, do the following:
Under 'Home Directory', 'Virtual Directory', or
'Directory', click on the 'Configuration' button,
and then enter the App Mappings tab.

Click Add, and in the Executable box, type:
c:\php\php.exe (assuming that you have unzipped PHP in c:\php\).

In the Extension box, type the file name extension you want
associated with PHP scripts. Leave 'Method exclusions'
blank, and check the Script engine checkbox. You may also
like to check the 'check that file exists' box - for a small
performance penalty, IIS (or PWS) will check that the script
file exists and sort out authentication before firing up php.
This means that you will get sensible 404 style error messages
instead of cgi errors complaing that php did not output any data.

You must repeat from 'Click Add...' for each extension you
want associated with PHP scripts.
(.php is recommended. although .phtml and .php3 may be
required for legacy applications.)

Set up the appropriate security. (This is done in Internet
Service Manager), and if your NT Server uses NTFS file system,
add execute rights for I_USR_ to the directory that contains
php.exe

!NOTE!: Since 4.1.2, the php.ini setting cgi.force_redirect defaults to '1'
which effectively prevents the cgi from working within IIS. You need to set
up at least a minimal php.ini file with the following directive:

cgi.force_redirect = 0

If it doesn't work immidiately, make sure you have the php.ini file in the
right place (%SYSTEMROOT%\php.ini).



So you will fine under wht's to be done to make PHP runing CGI mode for all Windows platform using Apache Server :


Installing PHP for Apache as CGI binary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you wish to install PHP as a CGI binary, read this first:

http://www.cert.org/advisories/CA-1996-11.html

and then if you are really sure, insert these lines to your conf file:

ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php.exe"

Note, we consider installing PHP like this suicidal.

As a further precaution, we recommend you change the "/php/"
ScriptAlias to something more random, to prevent the binary being
called directly, which is a security risk.

Remember when you have finished to restart the server, for example,
NET STOP APACHE
followed by
NET START APACHE

To use the source code highlighting feature, add the following
line to your apache httpd.conf file:

AddType application/x-httpd-php-source .phps

Note, this will only work when you install php as a sapi module.
If you wish to use this feature with the cgi binary, create a new
file, and use the show_source("path/to/original_file.php"); function.
Guest

Post by Guest »

hi,

i have problems getting iis 4 into cgi mode....

i've done all changes as discribed

Code: Select all

If you want to use the CGI binary, do the following: 
Under 'Home Directory', 'Virtual Directory', or 
'Directory', click on the 'Configuration' button, 
and then enter the App Mappings tab. 

Click Add, and in the Executable box, type: 
c:\php\php.exe (assuming that you have unzipped PHP in c:\php\). 

In the Extension box, type the file name extension you want 
associated with PHP scripts. Leave 'Method exclusions' 
blank, and check the Script engine checkbox. You may also 
like to check the 'check that file exists' box - for a small 
performance penalty, IIS (or PWS) will check that the script 
file exists and sort out authentication before firing up php. 
This means that you will get sensible 404 style error messages 
instead of cgi errors complaing that php did not output any data. 

You must repeat from 'Click Add...' for each extension you 
want associated with PHP scripts. 
(.php is recommended. although .phtml and .php3 may be 
required for legacy applications.) 

Set up the appropriate security. (This is done in Internet 
Service Manager), and if your NT Server uses NTFS file system, 
add execute rights for I_USR_ to the directory that contains 
php.exe 
can somebody help me please??
Christiaan

Post by Christiaan »

I am having major problem with 0.8. the session hangs very often. :cry:
I have to close my browser. I think i have the same error like discribe here.
Running W2K and Apache. but you say:
Note, we consider installing PHP like this suicidal.
But what other option do we have ? :cry:

Christiaan
lucky
Cacti User
Posts: 62
Joined: Mon Sep 30, 2002 3:23 am
Location: Germany

Post by lucky »

hi,

i updated cacti 0.68 to cacti 0.81 and have some problems with php and iis

Code: Select all

Security Alert! The PHP CGI cannot be accessed directly. 
This PHP CGI binary was compiled with force-cgi-redirect enabled. This means that a page will only be served up if the REDIRECT_STATUS CGI variable is set, e.g. via an Apache Action directive.

For more information as to why this behaviour exists, see the manual page for CGI security.

For more information about changing this behaviour or re-enabling this webserver, consult the installation file that came with this distribution, or visit the manual page.
i'm running a w2k server with iis and php4.3.2 in cgi mode...
i've done all settings as dicribed in this threade.

i've also set

Code: Select all

cgi.force_redirect = 0
cgi.redirect_status_event = 0
and also make changes in the registry...

can somebody help?? thx
Iluz

Same problem

Post by Iluz »

Hi,

Same problem on my side :-( and don't want to use CGI :-(((
and still no correction from php.net (4.3.3RC3 checked and tested)

Using :
W2K
Apache 1.3.27
PHP 4.3.0 or 4.3.3RC3
Cacti 0.8.2a

Is there anything to do rather than calling popen() then fpassthru() ? I.e another workaround ?

Does it means it's IMPOSSIBLE to run it on Win without CGI because of this bug ?

Iluz
EmmanuelJacobs

Can someone post more detail about the problem ?

Post by EmmanuelJacobs »

Which php module, which lines, which functions, etc...

Sincerely yours,

Emmanuel
Guest

PHP Apache CGI Mode

Post by Guest »

How do I set apache to work with PHP in CGI mode so that cacti should run?
I dont know much about apache and PHP so please give me an detailed advise.
thx
VeSS

Post by VeSS »

Has anything been done about this? Im at the point of installing VMWare and running linux inside of Windows (I need windows).

When i try to run Apache under CGI mode, i get the Trim error. When i try to run as a modual, i get the blocked graph's.

I also tried on IIS, same thing. Either TRIM() error or just does not work.
raX
Lead Developer
Posts: 2243
Joined: Sat Oct 13, 2001 7:00 pm
Location: Carlisle, PA
Contact:

Post by raX »

VeSS wrote:Has anything been done about this? Im at the point of installing VMWare and running linux inside of Windows (I need windows).

When i try to run Apache under CGI mode, i get the Trim error. When i try to run as a modual, i get the blocked graph's.

I also tried on IIS, same thing. Either TRIM() error or just does not work.
I know of no fix yet using PHP 4.2.3 by my count. I am still keeping my fingers crossed though. About the trim problem, make sure to check out the following thread (if you haven't already):

http://www.raxnet.net/board/viewtopic.p ... asc&start=

-Ian
Guest

Post by Guest »

I'm getting what I assume is this problem even running php in cgi mode. I can generate the graphs with rrdtool from the command line and also by putting in the 'html export path'... is there no other possible work arounds?

BTW, when using the parameters generated by Cacti from the command line with rrdtool it was necessary to remove the space tacked on the end of the $command_line and at the beginning of the error output string "2>&1". I trimmed these in rrd_functions.php chasing this problem but still get no graph.
Arc
Posts: 1
Joined: Tue Sep 23, 2003 9:09 am

Post by Arc »

Anonymous wrote:I'm getting what I assume is this problem even running php in cgi mode. I can generate the graphs with rrdtool from the command line and also by putting in the 'html export path'... is there no other possible work arounds?

BTW, when using the parameters generated by Cacti from the command line with rrdtool it was necessary to remove the space tacked on the end of the $command_line and at the beginning of the error output string "2>&1". I trimmed these in rrd_functions.php chasing this problem but still get no graph.
Registered now and quoting myself since I can't edit the above :) Ignore that second paragraph, further investigation revealed my error. The first part is still what I'm experiencing however.

Also, can someone confirm that php in cgi mode with IIS (not Apache) does overcome this issue because it isn't working for me. This is still assuming the symptoms described above are a result of this issue...
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests