Hi folks,
i have a problem using a PHP script as a custom handler in Apache.
What i wanna do is this:
Whenever a .html file is requested by a browser, i want Apache to call a
CGI that outputs a header, then the requested file and then a footer.
I want to use PHP for this, as i also want to do some template parsing.
Well, basically, this can be done using Apache's mod_action module,
where a custom handler can be defined for a certain filetype.
This does work correctly. If i request a .html file, the handler is
activated.
The strange thing is this: PHP does not output anything but the html header!
This is my custom handler file:
------------<htmlhandler.cg i>---------------
#!/bin/bash
/usr/bin/php-cgi test.php
--------------------------------------------
You see, php-cgi is called to execute test.php, which looks like this:
------------<test.php>----------------------
<?php
phpinfo();
?>
--------------------------------------------
So, what i would expect is, that the PHP info page is being sent to the
browser, which is not the case. All that is sent back is the .html file
i requested. And the strange thing is: If i execute the CGI from
commandline, i get all the phpinfo output! It just doesn't work when
called by apache!
You might think that the handler is not activated at all, but it is,
because if i change something in the custom handler config, like
spelling the filename wrong, i get a server error.
Also, i tried this using php-cgi directly, like this:
------------<htmlhandler.cg i>---------------
#!/usr/bin/php-cgi
<?php
phpinfo();
?>
--------------------------------------------
Which just gives me back the exact same results (just the requested
..html file).
Now for the funny part:
I also tried to do this using bash commands, like this:
------------<htmlhandler.cg i>---------------
#!/bin/bash
echo "Content-Type: text/html"
echo ""
echo "Hello World"
--------------------------------------------
This one works!! Hello world is being sent to the browser!
I am quite desperate, don't know what's left to try. Any ideas?
By the way, i'm using Apache 2.0.40 and PHP 3.3.8.
Thanks in Advance,
Tobias
i have a problem using a PHP script as a custom handler in Apache.
What i wanna do is this:
Whenever a .html file is requested by a browser, i want Apache to call a
CGI that outputs a header, then the requested file and then a footer.
I want to use PHP for this, as i also want to do some template parsing.
Well, basically, this can be done using Apache's mod_action module,
where a custom handler can be defined for a certain filetype.
This does work correctly. If i request a .html file, the handler is
activated.
The strange thing is this: PHP does not output anything but the html header!
This is my custom handler file:
------------<htmlhandler.cg i>---------------
#!/bin/bash
/usr/bin/php-cgi test.php
--------------------------------------------
You see, php-cgi is called to execute test.php, which looks like this:
------------<test.php>----------------------
<?php
phpinfo();
?>
--------------------------------------------
So, what i would expect is, that the PHP info page is being sent to the
browser, which is not the case. All that is sent back is the .html file
i requested. And the strange thing is: If i execute the CGI from
commandline, i get all the phpinfo output! It just doesn't work when
called by apache!
You might think that the handler is not activated at all, but it is,
because if i change something in the custom handler config, like
spelling the filename wrong, i get a server error.
Also, i tried this using php-cgi directly, like this:
------------<htmlhandler.cg i>---------------
#!/usr/bin/php-cgi
<?php
phpinfo();
?>
--------------------------------------------
Which just gives me back the exact same results (just the requested
..html file).
Now for the funny part:
I also tried to do this using bash commands, like this:
------------<htmlhandler.cg i>---------------
#!/bin/bash
echo "Content-Type: text/html"
echo ""
echo "Hello World"
--------------------------------------------
This one works!! Hello world is being sent to the browser!
I am quite desperate, don't know what's left to try. Any ideas?
By the way, i'm using Apache 2.0.40 and PHP 3.3.8.
Thanks in Advance,
Tobias
Comment