PHP under CGI Directory

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

    PHP under CGI Directory

    Hi all

    I was told by my hosting company that all the PHP files I wasnted to
    upload must be put under the CGI directory. I've done that and all I
    get when trying to access those php files is the following message:

    500 Server Error
    The server encountered an internal error or misconfiguratio n and was
    unable to complete your request.

    Error: HTTPd: malformed header from script

    I think this is because the server treats the files as cgi. Is there a
    directive I must include on my PHPs so the server may know what kind
    of files they are???

    TIA
  • Andy Hassall

    #2
    Re: PHP under CGI Directory

    On 16 Mar 2004 14:46:44 -0800, hlopez7@hotmail .com (Hector) wrote:
    [color=blue]
    >I was told by my hosting company that all the PHP files I wasnted to
    >upload must be put under the CGI directory. I've done that and all I
    >get when trying to access those php files is the following message:
    >
    >500 Server Error
    >The server encountered an internal error or misconfiguratio n and was
    >unable to complete your request.
    >
    >Error: HTTPd: malformed header from script
    >
    >I think this is because the server treats the files as cgi. Is there a
    >directive I must include on my PHPs so the server may know what kind
    >of files they are???[/color]

    If you're running PHP as CGI you need to include a #! line at the start of the
    script, as with any CGI script. For example:

    #!/usr/bin/php

    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

    Comment

    • Alex Shi

      #3
      Re: PHP under CGI Directory

      PHP and mod_perl are developed to get rid of CGI and they are
      ported to their module directly from web server. The idea to put
      PHP scripts under CGI directory sounds like to have a mule to pull
      a car.

      Anyway if you have to run PHP as CGI you must do following:
      1, change permission of PHP scripts to 755
      2. put a shebang line at the very begining of your scripts:
      #!/usr/bin/php -q
      <?php
      ....
      ?>

      Alex


      [color=blue]
      > Hi all
      >
      > I was told by my hosting company that all the PHP files I wasnted to
      > upload must be put under the CGI directory. I've done that and all I
      > get when trying to access those php files is the following message:
      >
      > 500 Server Error
      > The server encountered an internal error or misconfiguratio n and was
      > unable to complete your request.
      >
      > Error: HTTPd: malformed header from script
      >
      > I think this is because the server treats the files as cgi. Is there a
      > directive I must include on my PHPs so the server may know what kind
      > of files they are???
      >
      > TIA[/color]

      Comment

      • Hector

        #4
        Re: PHP under CGI Directory

        Thanks a lot. That worked just fine. Now I have a second problem. I'm
        trying open a connection to a MySQL database using mysql_connect() .
        Then I get this message:

        Call to unsupported or undefined function mysql_connect()

        I ran phpInfo() and I saw the PHP version on the server is 3.0.3 built
        in August 1998. I called the hosting company to ask if they included
        MySQL module when they compiled PHP. They told me their server is
        configured to run both 3.0.3 and 4.x version. Does any one know how to
        tell the server which version to use?

        Thaks again.


        "Alex Shi" <chpshi@stonix. com> wrote in message news:<kSR5c.973 32$Hl2.4856@nnt p-post.primus.ca> ...[color=blue]
        > PHP and mod_perl are developed to get rid of CGI and they are
        > ported to their module directly from web server. The idea to put
        > PHP scripts under CGI directory sounds like to have a mule to pull
        > a car.
        >
        > Anyway if you have to run PHP as CGI you must do following:
        > 1, change permission of PHP scripts to 755
        > 2. put a shebang line at the very begining of your scripts:
        > #!/usr/bin/php -q
        > <?php
        > ...
        > ?>
        >
        > Alex
        >
        >
        >[color=green]
        > > Hi all
        > >
        > > I was told by my hosting company that all the PHP files I wasnted to
        > > upload must be put under the CGI directory. I've done that and all I
        > > get when trying to access those php files is the following message:
        > >
        > > 500 Server Error
        > > The server encountered an internal error or misconfiguratio n and was
        > > unable to complete your request.
        > >
        > > Error: HTTPd: malformed header from script
        > >
        > > I think this is because the server treats the files as cgi. Is there a
        > > directive I must include on my PHPs so the server may know what kind
        > > of files they are???
        > >
        > > TIA[/color][/color]

        Comment

        • Andy Hassall

          #5
          Re: PHP under CGI Directory

          On 17 Mar 2004 15:11:26 -0800, hlopez7@hotmail .com (Hector) wrote:
          [color=blue][color=green]
          >> 2. put a shebang line at the very begining of your scripts:
          >> #!/usr/bin/php -q
          >> <?php
          >> ...[/color]
          >
          >Thanks a lot. That worked just fine. Now I have a second problem. I'm
          >trying open a connection to a MySQL database using mysql_connect() .
          >Then I get this message:
          >
          >Call to unsupported or undefined function mysql_connect()
          >
          >I ran phpInfo() and I saw the PHP version on the server is 3.0.3 built
          >in August 1998. I called the hosting company to ask if they included
          >MySQL module when they compiled PHP. They told me their server is
          >configured to run both 3.0.3 and 4.x version. Does any one know how to
          >tell the server which version to use?[/color]

          Ask your provider where they installed the 4.x PHP interpreter. It would
          appear that /usr/bin/php is the 3.0.3 version.

          --
          Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
          <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

          Comment

          • Hector

            #6
            Re: PHP under CGI Directory

            Andy Hassall <andy@andyh.co. uk> wrote in message news:<lnnh50lcm b6vtk941dnrbdte 4o9plgtcpv@4ax. com>...[color=blue]
            > On 17 Mar 2004 15:11:26 -0800, hlopez7@hotmail .com (Hector) wrote:
            >[color=green][color=darkred]
            > >> 2. put a shebang line at the very begining of your scripts:
            > >> #!/usr/bin/php -q
            > >> <?php
            > >> ...[/color]
            > >
            > >Thanks a lot. That worked just fine. Now I have a second problem. I'm
            > >trying open a connection to a MySQL database using mysql_connect() .
            > >Then I get this message:
            > >
            > >Call to unsupported or undefined function mysql_connect()
            > >
            > >I ran phpInfo() and I saw the PHP version on the server is 3.0.3 built
            > >in August 1998. I called the hosting company to ask if they included
            > >MySQL module when they compiled PHP. They told me their server is
            > >configured to run both 3.0.3 and 4.x version. Does any one know how to
            > >tell the server which version to use?[/color]
            >
            > Ask your provider where they installed the 4.x PHP interpreter. It would
            > appear that /usr/bin/php is the 3.0.3 version.[/color]

            You were right, /usr/bin/php is version 3.0.3; version 4.x was
            /usr/bin/php4. You guys are good! Now I need to solve a redirection
            problem. I know redirection is done using header("Locatio n:
            mysite.com"), but the issue here is that because the sh-bang line, php
            tells me that the headers were already sent when it gets to the header
            function. I even tried using ob_start() at the begining of the script
            and still the same error appears. Any help on this one will be highly
            appreciated.

            Comment

            • Andy Hassall

              #7
              Re: PHP under CGI Directory

              On 18 Mar 2004 13:42:35 -0800, hlopez7@hotmail .com (Hector) wrote:
              [color=blue]
              >You were right, /usr/bin/php is version 3.0.3; version 4.x was
              >/usr/bin/php4. You guys are good! Now I need to solve a redirection
              >problem. I know redirection is done using header("Locatio n:
              >mysite.com") , but the issue here is that because the sh-bang line, php
              >tells me that the headers were already sent when it gets to the header
              >function.[/color]

              Hm - not convinced yet here. I admit I don't have much experience of running
              PHP as CGI - I always run it as an Apache module. But I don't think the simple
              presence of a shebang and running as CGI means you cannot send headers? It
              doesn't appear to match the behaviour of PHP when you run it from the command
              line and forget to use '-q' - it only starts sending headers when it's run the
              whole script.
              [color=blue]
              > I even tried using ob_start() at the begining of the script
              >and still the same error appears. Any help on this one will be highly
              >appreciated.[/color]

              Please post a minimal runnable example that demonstrates your problem?

              --
              Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
              <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

              Comment

              • Hector

                #8
                Re: PHP under CGI Directory

                Andy Hassall <andy@andyh.co. uk> wrote in message news:<r07k501ap 8krfgbb9q526ic1 t49k9jvjt1@4ax. com>...[color=blue]
                > On 18 Mar 2004 13:42:35 -0800, hlopez7@hotmail .com (Hector) wrote:
                >[color=green]
                > >You were right, /usr/bin/php is version 3.0.3; version 4.x was
                > >/usr/bin/php4. You guys are good! Now I need to solve a redirection
                > >problem. I know redirection is done using header("Locatio n:
                > >mysite.com") , but the issue here is that because the sh-bang line, php
                > >tells me that the headers were already sent when it gets to the header
                > >function.[/color]
                >
                > Hm - not convinced yet here. I admit I don't have much experience of running
                > PHP as CGI - I always run it as an Apache module. But I don't think the simple
                > presence of a shebang and running as CGI means you cannot send headers? It
                > doesn't appear to match the behaviour of PHP when you run it from the command
                > line and forget to use '-q' - it only starts sending headers when it's run the
                > whole script.
                >[color=green]
                > > I even tried using ob_start() at the begining of the script
                > >and still the same error appears. Any help on this one will be highly
                > >appreciated.[/color]
                >
                > Please post a minimal runnable example that demonstrates your problem?[/color]

                Ok. This is an excerpt of my script. Not very sophisticated I must
                add. I moved the header function call to the very top of my script
                just for testing purposes. As you can see, there is not other output
                sent before the header(). Below is also the message I get. Originally,
                this script is intended to add a row to a table in a MySQL database
                with information taken from the user. When that is done, I intend to
                take the user to a "Thank you" page located outside the CGI directory.
                The record-adding part is ready. It is the redirection what's driving
                me nuts.


                #!/usr/bin/php4 -q
                <html>
                <body>
                <?php
                header( "Location: www.mywebsite.c om/thanks.html" );
                exit;

                Comment

                • Andy Hassall

                  #9
                  Re: PHP under CGI Directory

                  On 19 Mar 2004 08:17:19 -0800, hlopez7@hotmail .com (Hector) wrote:
                  [color=blue]
                  >Ok. This is an excerpt of my script. Not very sophisticated I must
                  >add. I moved the header function call to the very top of my script
                  >just for testing purposes. As you can see, there is not other output
                  >sent before the header(). Below is also the message I get. Originally,
                  >this script is intended to add a row to a table in a MySQL database
                  >with information taken from the user. When that is done, I intend to
                  >take the user to a "Thank you" page located outside the CGI directory.
                  >The record-adding part is ready. It is the redirection what's driving
                  >me nuts.
                  >
                  >#!/usr/bin/php4 -q[/color]

                  I don't think you want -q here - you DO want PHP to send out HTTP headers in
                  response to CGI requests. -q is for command-line usage.
                  [color=blue]
                  ><html>
                  ><body>[/color]

                  So you've started sending data out already here.
                  [color=blue]
                  ><?php
                  > header( "Location: www.mywebsite.c om/thanks.html" );[/color]

                  So this fails with ...
                  [color=blue]
                  >Warning: Cannot add header information - headers already sent by
                  >(output started at /cgi/displayInfo.php :4) in /cgi/displayInfo.php on
                  >line 5[/color]

                  ... this error.

                  Line 1 should be the shebag. Line 2 should be <?php. You should then make sure
                  your header() call comes before anything else is output.

                  --
                  Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
                  <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

                  Comment

                  Working...