apache php cgi install problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joseph S.

    apache php cgi install problem

    Hi,
    I am trying to install PHP 5.0.4 on Apache 2.0.54 on WinXP Pro SP2 as a
    cgi binary.

    Apache2 directory is c:/Apache2
    htdocs is c:/Apache2/htdocs

    php is installed in c:/php
    This contains php.ini, php-cgi.exe and php5ts.dll and other files
    required for the module method of php installation are also present,
    but i think additional files being present should not cause any problem

    Directory containing php scripts is C:/Apache2/htdocs/php

    My httpd.conf file has

    #----------------------------------------------------------
    ScriptAlias /php/ "C:/Apache2/htdocs/php/"
    AddType application/x-httpd-php .php
    Action application/x-httpd-php "C:/php/php-cgi.exe"
    #ScriptAliasMat ch ^/php(.*) C:/Apache2/htdocs/php$1
    #----------------------------------------------------------

    I get the error
    [Wed Feb 22 15:01:18 2006] [error] [client 127.0.0.1]
    C:/Apache2/htdocs/php/index.php is not executable; ensure interpreted
    scripts have "#!" first line
    [Wed Feb 22 15:01:18 2006] [error] [client 127.0.0.1] (9)Bad file
    descriptor: don't know how to spawn child process:
    C:/Apache2/htdocs/php/index.php

    in the Apache error log.

    What could be the error?

    I have no experience in CGI - I only know it stands for Common Gateway
    Interface - is there something needed to be read up first?

    I assume when run in CGI mode, whatever you put in your "cgi" diectory
    (here it is c:/Apache2/htdocs/php) it will be treated as a script.
    Because if I try http://localhost/php/file.htm it still gives the same
    error.

    Also, if I put #! on the first line I get
    [Wed Feb 22 15:33:45 2006] [error] [client 127.0.0.1] (OS 2)The system
    cannot find the file specified. : couldn't create child process:
    720002: index.php
    [Wed Feb 22 15:33:45 2006] [error] [client 127.0.0.1] (OS 2)The system
    cannot find the file specified. : couldn't spawn child process:
    C:/Apache2/htdocs/php/index.php
    or
    [Wed Feb 22 15:36:18 2006] [error] [client 127.0.0.1] (OS 193)%1 is not
    a valid Win32 application. : couldn't create child process: 720193:
    index.php
    [Wed Feb 22 15:36:18 2006] [error] [client 127.0.0.1] (OS 193)%1 is not
    a valid Win32 application. : couldn't spawn child process:
    C:/Apache2/htdocs/php/index.php

    Any suggested readings?
    I've googled the web and Google Groups but not able to get anything
    newer than what i know so far.

    TIA,
    JS.

  • Erwin Moller

    #2
    Re: apache php cgi install problem

    Joseph S. wrote:
    [color=blue]
    > Hi,
    > I am trying to install PHP 5.0.4 on Apache 2.0.54 on WinXP Pro SP2 as a
    > cgi binary.
    >
    > Apache2 directory is c:/Apache2
    > htdocs is c:/Apache2/htdocs
    >
    > php is installed in c:/php
    > This contains php.ini, php-cgi.exe and php5ts.dll and other files
    > required for the module method of php installation are also present,
    > but i think additional files being present should not cause any problem
    >
    > Directory containing php scripts is C:/Apache2/htdocs/php
    >
    > My httpd.conf file has
    >
    > #----------------------------------------------------------
    > ScriptAlias /php/ "C:/Apache2/htdocs/php/"
    > AddType application/x-httpd-php .php
    > Action application/x-httpd-php "C:/php/php-cgi.exe"
    > #ScriptAliasMat ch ^/php(.*) C:/Apache2/htdocs/php$1
    > #----------------------------------------------------------
    >
    > I get the error
    > [Wed Feb 22 15:01:18 2006] [error] [client 127.0.0.1]
    > C:/Apache2/htdocs/php/index.php is not executable; ensure interpreted
    > scripts have "#!" first line
    > [Wed Feb 22 15:01:18 2006] [error] [client 127.0.0.1] (9)Bad file
    > descriptor: don't know how to spawn child process:
    > C:/Apache2/htdocs/php/index.php
    >
    > in the Apache error log.
    >
    > What could be the error?
    >
    > I have no experience in CGI - I only know it stands for Common Gateway
    > Interface - is there something needed to be read up first?
    >
    > I assume when run in CGI mode, whatever you put in your "cgi" diectory
    > (here it is c:/Apache2/htdocs/php) it will be treated as a script.
    > Because if I try http://localhost/php/file.htm it still gives the same
    > error.
    >
    > Also, if I put #! on the first line I get
    > [Wed Feb 22 15:33:45 2006] [error] [client 127.0.0.1] (OS 2)The system
    > cannot find the file specified. : couldn't create child process:
    > 720002: index.php
    > [Wed Feb 22 15:33:45 2006] [error] [client 127.0.0.1] (OS 2)The system
    > cannot find the file specified. : couldn't spawn child process:
    > C:/Apache2/htdocs/php/index.php
    > or
    > [Wed Feb 22 15:36:18 2006] [error] [client 127.0.0.1] (OS 193)%1 is not
    > a valid Win32 application. : couldn't create child process: 720193:
    > index.php
    > [Wed Feb 22 15:36:18 2006] [error] [client 127.0.0.1] (OS 193)%1 is not
    > a valid Win32 application. : couldn't spawn child process:
    > C:/Apache2/htdocs/php/index.php
    >
    > Any suggested readings?
    > I've googled the web and Google Groups but not able to get anything
    > newer than what i know so far.
    >
    > TIA,
    > JS.[/color]


    Hi,

    Well, I don't use XP, but did you read this?



    Regards,
    Erwin Moller

    Comment

    • Christopher Pettet

      #3
      Re: apache php cgi install problem

      Have you done a PHPInfo? If you can't get this to work then you haven't
      installed php correctly.

      Create a page simply put this in it...

      <?phpinfo();? >

      Save the page to your root remembering to give it the php extension. I call
      mine phpinfo.php. Once you've done that, see if you can access the page. I
      personally prefer to use the isapi version of php (php5isapi.dll,
      php5apache2.dll in your case) as this is loaded at the start rather than on
      demand.


      "Joseph S." <js_dev@rediffm ail.com> wrote in message
      news:1140602755 .136247.74340@o 13g2000cwo.goog legroups.com...[color=blue]
      > Hi,
      > I am trying to install PHP 5.0.4 on Apache 2.0.54 on WinXP Pro SP2 as a
      > cgi binary.
      >
      > Apache2 directory is c:/Apache2
      > htdocs is c:/Apache2/htdocs
      >
      > php is installed in c:/php
      > This contains php.ini, php-cgi.exe and php5ts.dll and other files
      > required for the module method of php installation are also present,
      > but i think additional files being present should not cause any problem
      >
      > Directory containing php scripts is C:/Apache2/htdocs/php
      >
      > My httpd.conf file has
      >
      > #----------------------------------------------------------
      > ScriptAlias /php/ "C:/Apache2/htdocs/php/"
      > AddType application/x-httpd-php .php
      > Action application/x-httpd-php "C:/php/php-cgi.exe"
      > #ScriptAliasMat ch ^/php(.*) C:/Apache2/htdocs/php$1
      > #----------------------------------------------------------
      >
      > I get the error
      > [Wed Feb 22 15:01:18 2006] [error] [client 127.0.0.1]
      > C:/Apache2/htdocs/php/index.php is not executable; ensure interpreted
      > scripts have "#!" first line
      > [Wed Feb 22 15:01:18 2006] [error] [client 127.0.0.1] (9)Bad file
      > descriptor: don't know how to spawn child process:
      > C:/Apache2/htdocs/php/index.php
      >
      > in the Apache error log.
      >
      > What could be the error?
      >
      > I have no experience in CGI - I only know it stands for Common Gateway
      > Interface - is there something needed to be read up first?
      >
      > I assume when run in CGI mode, whatever you put in your "cgi" diectory
      > (here it is c:/Apache2/htdocs/php) it will be treated as a script.
      > Because if I try http://localhost/php/file.htm it still gives the same
      > error.
      >
      > Also, if I put #! on the first line I get
      > [Wed Feb 22 15:33:45 2006] [error] [client 127.0.0.1] (OS 2)The system
      > cannot find the file specified. : couldn't create child process:
      > 720002: index.php
      > [Wed Feb 22 15:33:45 2006] [error] [client 127.0.0.1] (OS 2)The system
      > cannot find the file specified. : couldn't spawn child process:
      > C:/Apache2/htdocs/php/index.php
      > or
      > [Wed Feb 22 15:36:18 2006] [error] [client 127.0.0.1] (OS 193)%1 is not
      > a valid Win32 application. : couldn't create child process: 720193:
      > index.php
      > [Wed Feb 22 15:36:18 2006] [error] [client 127.0.0.1] (OS 193)%1 is not
      > a valid Win32 application. : couldn't spawn child process:
      > C:/Apache2/htdocs/php/index.php
      >
      > Any suggested readings?
      > I've googled the web and Google Groups but not able to get anything
      > newer than what i know so far.
      >
      > TIA,
      > JS.
      >[/color]


      Comment

      • Joseph S.

        #4
        Re: apache php cgi install problem

        hi,
        thanks for the replies.
        (1) I am using my setup only for testing and development, so I do not
        have to worry about the reliability/stability of PHP 5/Apache2 in CGI
        mode on WIndows at the moment. The deployment server is linux.

        (2)[color=blue]
        > Have you done a PHPInfo? If you can't get this to work then you haven't
        > installed php correctly.
        > Create a page simply put this in it...
        > <?phpinfo();? >[/color]
        Tried that out. Surprisingly, see
        http://in.php.net/manual/en/security.cgi-bin.shell.php : it says you
        have to put the "shebang"(# !) line on top of each script if you are
        running the code in CGI mode !
        Tried that out only to get a nicer error in the logs:
        ----------start-------------
        Premature end of script headers: index.php
        <b>Security Alert!</b> The PHP CGI cannot be accessed directly.
        <p>This PHP CGI binary was compiled with force-cgi-redirect enabled.
        This
        means that a page will only be served up if the REDIRECT_STATUS CGI
        variable is
        set, e.g. via an Apache Action directive.</p>
        <p>For more information as to <i>why</i> this behaviour exists, see the
        <a href="http://php.net/security.cgi-bin">manual page for CGI
        security</a>.</p>
        <p>For more information about changing this behaviour or re-enabling
        this webserver,
        consult the installation file that came with this distribution, or
        visit
        <a href="http://php.net/install.windows ">the manual page</a>.</p>
        ----------end-----------
        All I needed to do was to set the value of the REDIRECT_STATUS CGI
        variable.
        This I did by adding a line below the Action application/x-httpd-php
        line in httpd.conf :

        SetEnv REDIRECT_STATUS On

        This is clearly a dirty hack. And I dont think it solves the problem
        that was being addressed by the error message. If my understanding is
        not wrong, it is like this:
        Some component of the system (either Apache or PHP) needs to know that
        the request for the script is not direct (by direct typing of url e.g.
        http://my.host/cgi-bin/php?/etc/passwd or
        http://my.host/cgi-bin/php/secret/doc.html etc)
        but redirected from Apache by either Alias or Rewrite or something.
        The correct value of REDIRECT_STATUS will differentiate between direct
        typing and Apache redirection.
        Anyways, it is working for now.
        Direct access to the php cgi executable in my case is not possible
        because it is outside the document root.
        However, the serious issue of writing the #! line is present yet. It
        openly states the path to the php interpreter. If somehow the code is
        exposed, my interpreter path is there for all to see.

        However, that we'll see later.

        Regards,
        JS

        Comment

        Working...