php4-cgi doesn't read -c /path/to/config, php5-cgi does

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Huber

    php4-cgi doesn't read -c /path/to/config, php5-cgi does

    Hi

    I've got a really strange problem, and can't find out why it's not
    working as intended.

    in order to use php4 and 5 together on a webserver and the requirement
    for running as different users, I use suexec and a wrapper script for
    php files. to make it a bit clearer, i'll post the different snippets:

    httpd.conf:
    ScriptAlias /php-wrapper /home/httpd/phpwrapper/
    AddType application/x-httpd-php-5 php
    Action application/x-httpd-php-5 /php-wrapper/php5
    AddType application/x-httpd-php-4 php3 php4
    Action application/x-httpd-php-4 /php-wrapper/php4

    resulting in using either /home/httpd/phpwrapper/php4 or
    /home/httpd/phpwrapper/php5 for php files

    the script for the wrappers (the checks only make sure the php.ini file
    can't be modified by our customers, it should be owned by root and not
    be writable):
    #!/bin/sh
    INI="${DOCUMENT _ROOT}/../etc/php.ini"
    if [[ -s "$INI" ]] && [[ ! -w "$INI" ]] && [[ ! -G "$INI" ]] && [[ ! -O
    "$INI" ]]
    then
    exec /usr/lib/php5/bin/php-cgi -c $INI ${PATH_TRANSLAT ED}
    else
    echo "Content-Type: text/plain"
    echo -e "\n\n"
    echo "Execution not allowed"
    fi

    the other wrapper is exactly the same exept it's executing the php4-cgi
    binary.

    suexec is already patched so it doesn't interfere with those scripts
    belowing to root. (I had make some exceptions, ie for the frontpage
    extensions which are now working perfectly)

    now the problem itself: under php5 all works perfectly. I have a default
    ini file (very restrictive) and the ini of the user (opening some
    directories with open_basedir). same under php4, only that it doesn't
    read the ini file at all. it just uses the default file, all extensions
    but not the file specified by -c

    paths and all are correct, and to make it even better: on the command
    line the same line works perfectly (as user and as root). I tried the
    same with -i for phpinfo() output.

    maybe its the heat, but I can't explain why that happens. especially the
    fact its working on command line is strange. the shellscript doesn't do
    anything else and yet it doesn't work.

    if anyone ever had a similar problem or maybe a hint about what to do to
    solve that problem, it would be highly appreciated.

    thanks alot and a nice day

    Stefan
  • Stefan Huber

    #2
    Re: php4-cgi doesn't read -c /path/to/config, php5-cgi does

    Stefan Huber wrote:
    Hi
    >
    I've got a really strange problem, and can't find out why it's not
    working as intended.
    >
    in order to use php4 and 5 together on a webserver and the requirement
    for running as different users, I use suexec and a wrapper script for
    php files. to make it a bit clearer, i'll post the different snippets:
    >
    httpd.conf:
    ScriptAlias /php-wrapper /home/httpd/phpwrapper/
    AddType application/x-httpd-php-5 php
    Action application/x-httpd-php-5 /php-wrapper/php5
    AddType application/x-httpd-php-4 php3 php4
    Action application/x-httpd-php-4 /php-wrapper/php4
    >
    resulting in using either /home/httpd/phpwrapper/php4 or
    /home/httpd/phpwrapper/php5 for php files
    >
    the script for the wrappers (the checks only make sure the php.ini file
    can't be modified by our customers, it should be owned by root and not
    be writable):
    #!/bin/sh
    INI="${DOCUMENT _ROOT}/../etc/php.ini"
    if [[ -s "$INI" ]] && [[ ! -w "$INI" ]] && [[ ! -G "$INI" ]] && [[ ! -O
    "$INI" ]]
    then
    exec /usr/lib/php5/bin/php-cgi -c $INI ${PATH_TRANSLAT ED}
    else
    echo "Content-Type: text/plain"
    echo -e "\n\n"
    echo "Execution not allowed"
    fi
    >
    the other wrapper is exactly the same exept it's executing the php4-cgi
    binary.
    >
    suexec is already patched so it doesn't interfere with those scripts
    belowing to root. (I had make some exceptions, ie for the frontpage
    extensions which are now working perfectly)
    >
    now the problem itself: under php5 all works perfectly. I have a default
    ini file (very restrictive) and the ini of the user (opening some
    directories with open_basedir). same under php4, only that it doesn't
    read the ini file at all. it just uses the default file, all extensions
    but not the file specified by -c
    >
    paths and all are correct, and to make it even better: on the command
    line the same line works perfectly (as user and as root). I tried the
    same with -i for phpinfo() output.
    >
    maybe its the heat, but I can't explain why that happens. especially the
    fact its working on command line is strange. the shellscript doesn't do
    anything else and yet it doesn't work.
    >
    if anyone ever had a similar problem or maybe a hint about what to do to
    solve that problem, it would be highly appreciated.
    >
    thanks alot and a nice day
    >
    Stefan
    I found out a tiny little bit:
    apache passes some env variables, 5 of them need to be unset, then it
    works. but those 4 aren't useless, I think:
    SCRIPT_FILENAME SERVER_NAME SERVER_SOFTWARE GATEWAY_INTERFA CE REQUEST_METHOD

    as soon as I let them through, cgi-php4 won't parse it's command line
    options (-c especially, but anything else too)

    I'll keep searching, but hoping someone could have clue whats the
    problem here..

    Stefan

    Comment

    • Stefan Huber

      #3
      Re: php4-cgi doesn't read -c /path/to/config, php5-cgi does

      Stefan Huber wrote:
      Stefan Huber wrote:
      >Hi
      >>
      >I've got a really strange problem, and can't find out why it's not
      >working as intended.
      >>
      >in order to use php4 and 5 together on a webserver and the requirement
      >for running as different users, I use suexec and a wrapper script for
      >php files. to make it a bit clearer, i'll post the different snippets:
      >>
      >httpd.conf:
      >ScriptAlias /php-wrapper /home/httpd/phpwrapper/
      >AddType application/x-httpd-php-5 php
      >Action application/x-httpd-php-5 /php-wrapper/php5
      >AddType application/x-httpd-php-4 php3 php4
      >Action application/x-httpd-php-4 /php-wrapper/php4
      >>
      >resulting in using either /home/httpd/phpwrapper/php4 or
      >/home/httpd/phpwrapper/php5 for php files
      >>
      >the script for the wrappers (the checks only make sure the php.ini file
      >can't be modified by our customers, it should be owned by root and not
      >be writable):
      >#!/bin/sh
      >INI="${DOCUMEN T_ROOT}/../etc/php.ini"
      >if [[ -s "$INI" ]] && [[ ! -w "$INI" ]] && [[ ! -G "$INI" ]] && [[ ! -O
      >"$INI" ]]
      >then
      > exec /usr/lib/php5/bin/php-cgi -c $INI ${PATH_TRANSLAT ED}
      >else
      > echo "Content-Type: text/plain"
      > echo -e "\n\n"
      > echo "Execution not allowed"
      >fi
      >>
      >the other wrapper is exactly the same exept it's executing the php4-cgi
      >binary.
      >>
      >suexec is already patched so it doesn't interfere with those scripts
      >belowing to root. (I had make some exceptions, ie for the frontpage
      >extensions which are now working perfectly)
      >>
      >now the problem itself: under php5 all works perfectly. I have a default
      >ini file (very restrictive) and the ini of the user (opening some
      >directories with open_basedir). same under php4, only that it doesn't
      >read the ini file at all. it just uses the default file, all extensions
      >but not the file specified by -c
      >>
      >paths and all are correct, and to make it even better: on the command
      >line the same line works perfectly (as user and as root). I tried the
      >same with -i for phpinfo() output.
      >>
      >maybe its the heat, but I can't explain why that happens. especially the
      >fact its working on command line is strange. the shellscript doesn't do
      >anything else and yet it doesn't work.
      >>
      >if anyone ever had a similar problem or maybe a hint about what to do to
      >solve that problem, it would be highly appreciated.
      >>
      >thanks alot and a nice day
      >>
      >Stefan
      >
      I found out a tiny little bit:
      apache passes some env variables, 5 of them need to be unset, then it
      works. but those 4 aren't useless, I think:
      SCRIPT_FILENAME SERVER_NAME SERVER_SOFTWARE GATEWAY_INTERFA CE REQUEST_METHOD
      >
      as soon as I let them through, cgi-php4 won't parse it's command line
      options (-c especially, but anything else too)
      >
      I'll keep searching, but hoping someone could have clue whats the
      problem here..
      >
      Stefan
      ah, I found the solution. its quite simple:
      the CGI version of php4 discards any command line options, using env
      variables instead. for a new ini file it's the PHPRC variable, which has
      to point to a directory rather then to a file (thats what I tested and
      not worked).
      php5 reads all command line args and also the variables.

      the simpler the problem the harder to find a solution ;-)

      Stefan

      Comment

      Working...