logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: php4 as CGI
Author
¤| battousai |¤



Joined: 12 Oct 2006
Posts: 12

PostPosted: Mon 30 Jun '08 14:10    Post subject: php4 as CGI Reply with quote

Hello,

Following the instructions on the php manual, aswell as the user
contributed notes I have managed to install php4 as CGI, next to an
already existing php5 module.

But I am not sure whether it works correctly. Below are the Directives I have added to apache's http.conf

Code:

ScriptAlias /php "J:/php4"
AddType application/x-httpd-php .php4
Action application/x-httpd-php "/php4/php.exe"
<Directory "J:/php4">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
ScriptInterpreterSource Registry-Strict


As you probably gathered from these entries, the php4 root is located on
J:\php4

So how can I test whether the php4 interpretter is actually being used?

I have created a php4 file that has phpinfo() in it, but when I run this file
it shows me the information of the php5 module that apache uses.

IMO the fact that the server was able to execute the .php4 file indicates
that the new setup works.

Note: I have apache2.2.3 installed

I humbly await your response Smile
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3091
Location: Hilversum, NL, EU

PostPosted: Mon 30 Jun '08 21:07    Post subject: Reply with quote

Long time ago I tried it, found in an old conf:

ScriptAlias /php4/ "J:/php4/"
AddType application/x-httpd-php4 .php4
Action application/x-httpd-php4 "/php4/php-cgi.exe"
SetEnv PHPRC J:/php4

(SetEnv PHPRC: where to find php.ini)


Steffen
Back to top
¤| battousai |¤



Joined: 12 Oct 2006
Posts: 12

PostPosted: Wed 02 Jul '08 13:49    Post subject: Reply with quote

Thanks for the reply Steffen,

I have modified the specific lines in http.conf so it now looks like this:
Code:
ScriptAlias /php/ "J:/php4/"
AddType application/x-httpd-php .php4
Action application/x-httpd-php "/php4/php.exe"
ScriptInterpreterSource Registry-Strict


But I didn't notice any changes. Also, when I run the php4info.php4 file It still says PHP version 5.1.6 (dunno if it should be like this)

Note:
According to the PHP Manual, the SetEnv directive is not required for Apache versions 2.0.x and above.

Edit:
Ok, so I went to the php manual, looked up the function reference for
domxml (as this is what i essentially got php4.4.8 for), looked up a
function that had a stated functionality with php4, pasted the example
code in a .php4 file, ran it and was greeted by a nice 'call to undefined
function' fatal error.

So I decided to swap the current phpmodule with php4. (so that i only
have php4 installed as a module and no cgi). Then I tried to restart
apache from the command line and it gave me a syntax error:
'Cannot load J:/php4/php4apache2.dll into the server: The specified
module could not be found.'
Code:

LoadModule php4_module "J:/php4/php4apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "J:/php4"


I checked & confirmed multiple times that the file is sitting in this directory & the name is exact.

I have reread the compatibility notes on php's install page and it doesn't seem to indicate php4.4.8 and apache2.2.x are incompatible :s

Maybe I'l just get Apache1.3.x and see if it that works

Might also be worth mentioning that I'm working on a WIN XP machine
Back to top
alex.w474



Joined: 20 Feb 2008
Posts: 11

PostPosted: Wed 02 Jul '08 16:27    Post subject: Reply with quote

Pay attention to
Quote:
Code:
ScriptAlias /php4/ "J:/php4/"


I suspect that you have two lines:
Code:

AddType application/x-httpd-php .php4
...
AddType application/x-httpd-php .php


because you have PHP5 already installed. So the last one overwrites settings for PHP4.
Use different type as Steffen described or consider this instruction:
http://www.witsuite.com/support/knowledge-base/manual-installation/install-php.php - it explains how to setup PHP to support multiple versions of the language on one Apache.

Quote:
According to the PHP Manual, the SetEnv directive is not required for Apache versions 2.0.x and above.


You right that it is not required, but you do not right because it should be specified so PHP knows where the PHP.ini resides.

Quote:
I have reread the compatibility notes on php's install page and it doesn't seem to indicate php4.4.8 and apache2.2.x are incompatible :s


It is compatible, I've use it on my Apache together with PHP5, both are CGI.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3091
Location: Hilversum, NL, EU

PostPosted: Wed 02 Jul '08 19:01    Post subject: Reply with quote

Did you try what I suggested exactly?

ScriptAlias /php4/ "J:/php4/"
AddType application/x-httpd-php4 .php4
Action application/x-httpd-php4 "/php4/php-cgi.exe"
SetEnv PHPRC J:/php4
Back to top
¤| battousai |¤



Joined: 12 Oct 2006
Posts: 12

PostPosted: Wed 02 Jul '08 19:52    Post subject: Reply with quote

When modefying the http.conf to use php4 I made sure to comment out all the lines regarding php5 and the cgi setup of php4
Code:

# PHP 5.1.6 Module
#LoadModule php5_module "J:/php5/php5apache2.dll"
#AddType application/x-httpd-php .php
#PHPIniDir "J:/php5"

# PHP 4.4.8 Module
LoadModule php4_module "J:/php4/php4apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "J:/php4"

# PHP 4.4.8 CGI
#ScriptAlias /php/ "J:/php4/"
#AddType application/x-httpd-php .php4
#Action application/x-httpd-php "/php4/php.exe"
#ScriptInterpreterSource Registry-Strict


I searched the rest of the file for other occurences of AddType that have php in it and i found the following
Code:

<IfModule mod_php5.c>
   AddType application/x-httpd-php .php
   AddType application/x-httpd-php .php3
   AddType application/x-httpd-php-source .phps
</IfModule>


I commented that out aswell, so now it only reads the configuration
directives for php4.
Then I stopped apache and started again but still I get the error of module
could not be found

Edit:
AFter some more googling, I stumbled across the website of devside.
Which states that the apache2 handler that comes with php4.4 & php5 .1doesn't work with apache2.2, so I have downloaded php4apache2_2.dll and this seems to work, I am now running php4.4.8 on apache2.2.3 Smile

Next I have to test running php4 as cgi and php5 as module again.
Back to top
alex.w474



Joined: 20 Feb 2008
Posts: 11

PostPosted: Wed 02 Jul '08 21:48    Post subject: Reply with quote

Code:

LoadModule php4_module "J:/php4/php4apache2.dll"


php4apache2.dll is for apache 2.0, not for apache 2.2. PHP4 does not work with apache 2.2 as module, only as CGI. And in PHP4 all handlers are located in sapi subfolder of your PHP installation folder.

So you just need to try this solution: http://www.witsuite.com/support/knowledge-base/manual-installation/install-php.php

Adapted to your directories:
Code:

ScriptAlias /php4/ "J:/php4/"
Action application/x-httpd-php4 "/php4/php.exe"
AddType application/x-httpd-php4 .php
<Directory "J:/php4">
    SetEnv PHPRC "J:\php4"
    SetEnv PATH "C:\WINDOWS;C:\WINDOWS\System32;J:\php4;J:\php4\dlls"
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
Back to top
alex.w474



Joined: 20 Feb 2008
Posts: 11

PostPosted: Wed 02 Jul '08 23:06    Post subject: Reply with quote

http://bugs.php.net/bug.php?id=39586&edit=1

Quote:

php4apache2.dll is PHP for Apache 2.0.x, not Apache 2.2.x.
We do not plan to release any PHP4 modules for Apache 2.2.x
Back to top
¤| battousai |¤



Joined: 12 Oct 2006
Posts: 12

PostPosted: Wed 02 Jul '08 23:09    Post subject: Reply with quote

Progress.

Alex, I have added the directived you addapted for my configuration but when i run the file I get 'No input file specified.'
this is the code of the file:
Code:

#!php
<?php

echo("does it work?");

?>


I have read the apache chapter on CGI and adapted the directives accordingly, with some added ones like Action & AddType.
Code:

ScriptAlias /cgi-bin/ "J:/php4/"
Action application/x-httpd-php "/php4/php.exe"
AddType application/x-httpd-php .php4
AddHandler cgi-script .php4

<Directory "J:/php4">
    SetEnv PHPRC "J:\php4"
    AllowOverride None
    Options +ExecCGI
    Order allow,deny
    Allow from all
</Directory>


With this configuration, when I try to load a php4 file I get a typical 'file not found' error and the following is added in the error log:
Quote:

Premature end of script headers: test.php4, referer: http://localhost:8080/files/cgi-bin/ Security Alert! The PHP CGI cannot be accessed directly., referer: http://localhost:8080/files/cgi-bin/ , referer: http://localhost:8080/files/cgi-bin/ This PHP CGI binary was compiled with force-cgi-redirect enabled. This, referer: http://localhost:8080/files/cgi-bin/ means that a page will only be served up if the REDIRECT_STATUS CGI variable is, referer: http://localhost:8080/files/cgi-bin/ set, e.g. via an Apache Action directive.

, referer: http://localhost:8080/files/cgi-bin/ For more information as to why this behaviour exists, see the manual page for CGI security.

, referer: http://localhost:8080/files/cgi-bin/ For more information about changing this behaviour or re-enabling this webserver,, referer: http://localhost:8080/files/cgi-bin/ consult the installation file that came with this distribution, or visit , referer: http://localhost:8080/files/cgi-bin/ the manual page.

, referer: http://localhost:8080/files/cgi-bin/


I know I might have disregarded some security issues here, but it's only on a local machine, and for testing purposes this time.
Anyway it's getting late and i need some sleep so i can look at the things with a fresh mind tommorow morning Smile

Note: This time, I disabled the php5 module
Back to top
¤| battousai |¤



Joined: 12 Oct 2006
Posts: 12

PostPosted: Fri 04 Jul '08 17:27    Post subject: Reply with quote

Even more progress.

I think the directives alex proposed are correct, because I'm getting 'No
the Internal Server Error page, which would indicate the script is atleast
being run partially, or the server tried to run the script correctly.

So these are the directives:
Code:

ScriptAlias /php/ "J:/php4/"
Action application/x-httpd-php "/php4/php.exe"
AddType application/x-httpd-php .php
<Directory "J:/php4">
    SetEnv PHPRC "J:/php4"
    SetEnv PATH "G:/WINDOWS;G:/WINDOWS/System32;J:/php4"
    AllowOverride None
    Options none
    Order allow,deny
    Allow from all
</Directory>


To clarify things some more:
- everything webserver related resides on a seperate partition J
- windows sits on G
- copied the php dll's to the php4 folder
- php4 is on J:\php4
- test.php sits in J:\php4
- in php.ini, cgi.force_redirect is set to 1
- in php.ini, doc_root is empty
- the php manual notes to convert forward-slashes to backslashes for path values in apache.
- both the php4 folder and apache\bin folder have been included in Window's PATH env

This is the code of test.php
Code:

#!J:/php4/php.exe
<?php

    echo("does it work?");

?>


I have tried running the script from window's command line and it works fine

So now I get the Page not found page of firefox when trying to load the
file. And in apache's error log I find the 'Premature end
of script headers
' error. The access log says: "GET /php4/test.php HTTP/1.1" 500 545

For the moment, I have set cgi.force_redirect to 0 and it works like a sharm. Atleast untill I can figure out the security part Razz

Side-Note: Atlast I have managed to get it working. after several days of rubbing my head I can rejoice Smile

I would also like to add som additional info:
- Note the requirement for forward-slashes to be converted to backslashes
for path values in httpd.conf, but either way works
- this setup worked fine when i had commented the Directory directive for php4
- An additional +ExecCGI option is not required for this setup to work

I hope this tread may help any future Apache admin that tries to setup php4 (or maybe later version) as CGI.
Thanks all for the support
Back to top
alex.w474



Joined: 20 Feb 2008
Posts: 11

PostPosted: Fri 04 Jul '08 17:37    Post subject: Reply with quote

Quote:
- copied the php dll's to the php4 folder

This step can be omitted if use
SetEnv PATH "C:\WINDOWS;C:\WINDOWS\System32;J:\php4;J:\php4\dlls"

Quote:
- test.php sits in J:\php4

I'm not sure that this is correct. Normally, PHP scripts are in web server document root folder.
Quote:
- both the php4 folder and apache\bin folder have been included in Window's PATH env

This is not required - Apache looks for dlls in its folder and "SetEnv PATH" is enough for PHP.

Quote:
#!J:/php4/php.exe


I think this is not required and may be deleted.
Back to top
¤| battousai |¤



Joined: 12 Oct 2006
Posts: 12

PostPosted: Fri 04 Jul '08 17:55    Post subject: Reply with quote

Indeed, I have tried omiting the shebang line and it works just as well. I
gues this is because the Action directive takes care of that. However i find
it a bit wierd that apache threw error on previous occasions when the
shebang line was not present.

I didn't quite get the meaning of the ScriptAlias directive in the beginning
and just ran test.php from a random location in the server folder structure.

So I test.php inside the php4 folder merely for testing perpouse and now I
understand it's workings. I have also change this folder to another location,
though not my server's docroot since i need a central location for all scripts
and want them seperate from the server.

After I got this to work, I changed the httpd.conf to include php5.1.6 as a
module.
Back to top
kanashii2



Joined: 25 Nov 2008
Posts: 1

PostPosted: Tue 25 Nov '08 21:12    Post subject: re Reply with quote

i had the same problem

#remove#

doc_root =
user_dir =

In log there whose corectly path i run php-cgi.php path c:/wwwroot and work
but in Apache No input file ... means error 404 on fastcgi

Set user_dir,doc_root to null and shuld be work Smile
Back to top


Reply to topic   Topic: php4 as CGI View previous topic :: View next topic
Post new topic   Forum Index -> Apache