php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39277 php-cgi does not parse command line arguments when running under Apache
Submitted: 2006-10-27 11:02 UTC Modified: 2006-11-12 18:53 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: nisoi at mail dot ru Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 4.4.4 OS: FreeBsd 6.1
Private report: No CVE-ID: None
 [2006-10-27 11:02 UTC] nisoi at mail dot ru
Description:
------------
PHP-4.4.4-cgi does not parse command line arguments when run under Apache (but parses it when run from shell). Php5 works fine in same situation.

I run php-4.4.4 as cgi under Apache/1.3.34. All requests for *.php are redirected to php-cgi with

Action php-script /cgi-bin/php4

/cgi-bin/php4 looks like this:

=== /cgi-bin/php4 ==>
#!/usr/local/php4/bin/php-cgi -c/home/scrtest/www/site1/public_html/php-c.ini
<== /cgi-bin/php4 ===

But phpinfo() says that it is using default config from /usr/local/php4/etc/php-cgi.ini. No other arguments are working: neither "-n", neither "-h", nor anything.

Even this trick:

=== /cgi-bin/php4 ==>
#!/bin/sh

/usr/local/php4/bin/php-cgi -c/home/scrtest/www/site1/public_html/php-c.ini
<== /cgi-bin/php4 ===

does not make php-cgi to take it's arguments. 

When I run same command from shell, php-cgi parses it's arguments correctly.

Reproduce code:
---------------
<?php

phpinfo();

?>


Expected result:
----------------
Want to see /home/scrtest/www/site1/public_html/php-c.ini as configuration file.


Actual result:
--------------
See /usr/local/php4/etc/php-cgi.ini as configuration file.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-31 12:17 UTC] nisoi at mail dot ru
I just tested this issue under Gentoo Linux. Same things happen: PHP does not pay any attention to command line arguments passed to php-cgi running under Apache.
 [2006-11-11 00:52 UTC] tony2001@php.net
Expected behaviour.
PHP CGI doesn't use commandline parameters when run in CGI mode (but it does use them when run in console mode).
 [2006-11-11 12:21 UTC] nisoi at mail dot ru
But PHP-5.1.2-CGI does interpret command line arguments while running under Apache. Also, php-4.4.2-cgi (not php-cli!) interprets these arguments while running from command line. Is this expected behavior too? 

I mean, all three ways PHP-cgis work cannot be correct at the same time.
 [2006-11-11 12:40 UTC] tony2001@php.net
>But PHP-5.1.2-CGI does interpret command line arguments
> while running under Apache

No, it doesn't. It's extremely easy to show:

# export SERVER_SOFTWARE=1
# ./sapi/cgi/php -i
Status: 404
X-Powered-By: PHP/5.1.2
Content-type: text/html

No input file specified.
# unset SERVER_SOFTWARE
# ./sapi/cgi/php -i
X-Powered-By: PHP/5.1.2
Content-type: text/html

<!DOCTYPE html PUBLIC ..........
 [2006-11-11 16:13 UTC] nisoi at mail dot ru
Well, you are right. Please forgive me for this.

But if so, then there is another... ehhm.. inconvenience. It is impossible to set custom php.ini via .htaccess for some directory.

When I use in .htaccess:

SetEnv PHPRC /home/user/public_html/

and if I redirect all *.php requests to /home/http/php4-cgi (which is just a symlink to php-cgi), Apache renames PHPRC to REDIRECT_PHPRC, because requests are redirected to another script. Thus, php does not recognize this variable and uses default /usr/local/etc/php.ini.

Of course, I can use a sh script instead of /home/http/php4-cgi, and export PHPRC there. This works. But there is absolutely unnecessary sh process in this case.

As a workaround, php could either recognize REDIRECT_PHPRC, or use -C argument in command line while working in CGI mode.
 [2006-11-12 18:53 UTC] tony2001@php.net
Duplicate of FR #37193.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 27 18:01:35 2024 UTC