Problems with CGI wrapper for PHP

Posted by user205878 on Stack Overflow See other posts from Stack Overflow or by user205878
Published on 2010-03-03T01:00:47Z Indexed on 2010/03/13 9:05 UTC
Read the original article Hit count: 435

Filed under:
|

I'm having a bugger of a time with a CGI wrapper for PHP. I know very little about CGI and PHP as CGI.

Here's what I know about the system:

  • Solaris 10 on a 386
  • Suhosin
  • PHP normally running as CGI, with cgiwrap (http://cgiwrap.sourceforge.net/). I am not able to find an example wrapper.cgi on the server to look at.
  • Shared hosting (virtual host), so I don't have access to Apache config. But the admins are not helpful. Switching hosts is not an option.
  • Options directive cannot be overridden in .htaccess (ExecCGI, for example).

.htaccess:

AddHandler php-handler .php  
Action php-handler "/bin/test.cgi"

~/public_html/bin/test.cgi:

#!/usr/bin/sh

# Without these 2 lines, I get an Internal Server Error
echo "Content-type: text/html"
echo ""

exec "/path/to/php-cgi" 'foo.php';

/bin/foo.php:

<?php 
echo "this is foo.php!";

Output of http://mysite.com/bin/test.cgi:

X-Powered-By: PHP/5.2.11 Content-type: text/html echo "Content-type: text/html" echo "" exec "/path/to//php-cgi" 'foo.php';

Output of http:/ /mysite.com/anypage.php:

X-Powered-By: PHP/5.2.11 Content-type: text/html echo "Content-type: text/html" echo "" exec "/path/to//php-cgi" 'foo.php';

The things I note are:

  • PHP is being executed, as noted by the X-Powered-By ... header.
  • The source of /bin/test.cgi is output in the results.
  • No matter what I put as the second argument of exec, it isn't passed to the php binary. I've tried '-i' to get phpinfo, '-v' to get the version...
  • When I execute test.cgi via the shell, I get the expected results (the argument is passed to php, and it is reflected in the output).

Any ideas about how to get this to work?

UPDATE

  • It appears that the reason the source of the test.cgi was appearing was due to errors. Anytime fatal error occurred, either within the cgi itself or with the command being executed by exec, it would cause the source of the cgi to appear.
  • Within test.cgi, I can get the proper output with exec "/path/to/php-cgi" -h (I get the same thing as I would from CLI).

© Stack Overflow or respective owner

Related posts about php

Related posts about cgi