CGI Shell Issues for PHP

I have from time to time using the CGI shell for PHP. I know very little about CGI and PHP as CGI.

Here is what I know about the system:

  • Solaris 10 on 386
  • Suhosin
  • PHP usually works like CGI, cgiwrap ( http://cgiwrap.sourceforge.net/ ). I can not find wrapper.cgi example on the server to look.
  • Shared hosting (virtual host), so I do not have access to the Apache configuration. But administrators do not help. Switching hosts is not an option.
  • The Options directive cannot be overridden in .htaccess (e.g. ExecCGI).

.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!";

The 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';

The 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';

I note the following:

  • PHP, X-Powered-By ....
  • /bin/test.cgi.
  • , exec, php. '-i' phpinfo, '-v', ...
  • test.cgi , ( php, ).

, ?

UPDATE

  • , , test.cgi, . , cgi, , exec, cgi.
  • test.cgi exec "/path/to/php-cgi" -h ( , CLI).
+3
4

php-cgi bin , , test.cgi.

+1

, :

  • , php script, php .

  • script exec "/path/to/php-cgi \"/path/to/script/foo.php\""

, .

EDIT

. , :

#!/bin/bash

/usr/bin/php-cgi "$@"

script PHP CGI, , Apache bash script .

+1

:

  • , . , -. PHP ( ). script.

  • , (, php-cgi /usr/bin/php-cgi, PHP CGI .

    ScriptAlias /local-bin /usr/bin
     AddHandler application/x-httpd-php5 php
     Action application/x-httpd-php5 /local-bin/php-cgi

    . php. php , .

+1

Are you getting an internal server error because it expects the file to contain Perl, not PHP code? I mean where are the tags <?php ?>(without them it is text and will not be processed like PHP). Guess you can't use AddType like this: I suggest AddType in the directive <Directory>- okay I think the rest is not affected (the path as a template is the problem). In addition, it exec()expects 3 parameters that must be enclosed in brackets - at least in PHP.

0
source

Source: https://habr.com/ru/post/1735160/


All Articles