I browsed through search results to try to find instructions on how to install php as a cgi and could not find detailed instructions on how to do this. The web server that is running is apache. It already has php installed, however I would like to be able have databases that cannot be modified by other users. In space on my web account, I placed php.ini and php.exe in a folder (titled php inside of a folder titled bin). At the top of a script that I titled test.cgi, I placed #!/home/myuser/bin/php, however, this returned an internal server error. Does the script have to have the actual path to php.exe? Are there any other ways to possibly fix the server error?

Any help would be appreciated.
Thanks in advance,
M

    M,

    When PHP is installed as CGI, it doesn't mean your scripts execute in the same way as a traditional CGI proggie. The basic difference between PHP as CGI and PHP as a module (or SAPI) is the way the interpreter is spawned. You tell the webserver which way you're going to be serving your content, tell it way extensions to look for, and then the server takes care of the rest. There is no cgi-bin for PHP, and you can only have PHP installed in one format. You'd need to convince your host to drop the existing setup🙂 You're better off exploring other options, like HTTP authentication, to protect individual files or folders. Check the header() section of the PHP Manual's function reference for examples of HTTP_AUTH. HTH,

    Cheers,

    Geoff A. Virgo

      I checked for those functions in the manual, however, they don't provide the functionality that I will need for some scripts. On my web server, the hosts actually suggest running php with the cgi line and .cgi extensions ( detailed on this help: https://kbase.newdream.net/index.cgi?area=1102) to add different parts to php as well as database security. This is in a personal user area of the server. The difficulty with this is that installation tutorials don't focus on this type of installation. If you have any tips on getting this to work I'd appreciate it.

      Thanks
      M

        9 months later

        I Cant believe this hasnt been answered yet. Im looking for a similar thing, and have had trouble finding anything.

        What I did was compile php with the option --disable-force-cgi-redirect

        then, add this line to the top of the script:
        #!/usr/bin/php (or whatever the path is)

        make it executable. run it from the command line to test.

        make sure the directory in apache has ExecCGI option enabled

        then in the httpd.conf:
        AddHandler cgi-script .cgi

        This should work just fine

        Chris

        ps. sorry this response is 8 months late...

          Write a Reply...