Forum Moderators: phranque

Message Too Old, No Replies

How to change default handler for .php?

Is htaccess the way to go?

         

jsruok

8:15 am on May 29, 2004 (gmt 0)

10+ Year Member



This message was first posted in PHP forum, but it's more Apache specific and I'm fighting against a deadline here, so any help from anybody is greatly appreciated. Thanks.

The message follows.


My web host's PHP doesn't provide curl, so I want to run .php files thru my own PHP parser. However, I don't want to rename all the .php files into .cgi files and add some #!/path/to/php as the first line.

Is it possible to change the default parser, somehow? So far, I've only tried playing with .htaccess file.

First I wrote

Action php-parser /path/to/php
AddType php-parser .php

and when I tried to access phpinfo.php I got the error message "The requested URL /path/to/php/phpinfo.php was not found on this server"

Then I tried

Action application/x-httpd-php /path/to/php

but that didn't do any good. phpinfo.php was still parsed by my host's PHP.

So the next shot was

Action application/x-httpd-php /path/to/php
AddType application/x-httpd-php php

which yielded the same error message as in the first case. So I figured application/x-httpd-php was not valid and tried only

AddType application/x-httpd-php foo

This way phpinfo.foo was parsed, as well as phpinfo.php. I cleared the .htaccess file one more time and typed

Action php-parser /path/to/php
AddType php-parser php

but that yielded the notorious error message "The requested URL /path/to/php/phpinfo.php was not found on this server".

gergoe

1:06 am on May 31, 2004 (gmt 0)

10+ Year Member



I never tried to do such a thing, and due to the lack of my linux knowledge, I can only give you hints:

Try the RemoveType and/or the RemoveHandler directives in your htaccess file. Read the corresponding part of the Apache documentation carefully, there is some caveat when you use them.

Try ScriptAlias and put the directory where your php parser is into the url, and use this aliased path instead:


ScriptAlias /myparser/ /path/to/php
Action application/x-httpd-php /myparser/php

The AddType is not necessary to be in your htaccess file. You'll need to use it only if you want to override the default setting (which put the application/x-httpd-php mime type on the php files). The only problem is that you can't use the ScriptAlias directive in htaccess files...

The last suggestion might be is to use the custom parser as a cgi binary from a php script, send the request via stdin and receive the parsed output from stdout and voila. Dirty and not nice at all, but could be that this is the only way if you don't have access to the Apache config.

Good luck

jsruok

9:39 am on May 31, 2004 (gmt 0)

10+ Year Member



Thanks gergoe.

I tried to apply RemoveType and RemoveHandler but they didn't change a thing.

Sadly, I can only use htaccess, so ScriptAlias cannot be used.

Apparently my last shot was

AddHandler my-handler .foo
Action my-handler /home/customers/logonetshop/php/bin/php.cgi

which gave me the Not found error ("The requested URL /path/to/php/bin/php.cgi/phpinfo.foo was not found on this server").

(The fact the it didn't work was kind of funny, because that was taken almost directly from an Apache manual example.) The /path/to/php/bin/php.cgi file contained only one line:

#!/path/to/php/bin/php

It read somewhere in the manual that Actions should be cgi-scripts. So I figured that would do the trick. Well, it didn't.

Augh.. I guess I'll just have to start renaming the .php files into .cgi and carry on that way..

Thanks for the help, though.

hcblue

7:57 am on Jun 14, 2004 (gmt 0)

10+ Year Member



Wouldn't the correct way to be using handlers?


Action php-script /cgi-bin/php
AddHandler php-script .php

and then put php in your cgi-bin directory and make it executable.

jsruok

10:20 am on Jun 15, 2004 (gmt 0)

10+ Year Member



Thanks, hcblue, but your solutions returns the same 404 error message as with the AddType:

Action php-parser /path/to/php
AddType php-parser .php

That is, phpinfo.php is located at /path/to/public_html/relative/path/to/phpinfo.php and I get the 404 error ("URL /path/to/php/relative/path/to/phpinfo.php not found").

I wouldn't know whether the AddHandler or AddType is the way to go, as neither of them works for me.