Page 1 of 1

How to run PHP script in "cgi mode"?

Posted: Fri Jul 02, 2004 9:22 pm
by tomfra
I know I can run a php script as CGI even if php has been installed as Apache module, if I put it in the cgi-bin folder, add #!/usr/bin/php (if php is installed at that location) as the first line and chmod it to 755.

But is there a way how to execute php scripts as cgi outside of the cgi-bin directory? Also, if I do install it in the cgi-bin folder, will such script have access to files outside of the cgi-bin folder (in the public_html root folder and subdirectories)?

Thanks!

Tomas

Re: How to run PHP script in "cgi mode"?

Posted: Fri Jul 02, 2004 10:36 pm
by redmonkey
tomfra wrote:I know I can run a php script as CGI even if php has been installed as Apache module, if I put it in the cgi-bin folder, add #!/usr/bin/php (if php is installed at that location) as the first line and chmod it to 755.
The last few versions of PHP that I have compiled as Apache modules have disabled the compiling of the CGI executable unless I actively specify with CGI at configure time, so you may not automatically have CGI support. The CLI executable is compilied by default so that may be what you have.
tomfra wrote:But is there a way how to execute php scripts as cgi outside of the cgi-bin directory?
That would be down to the configuration of your web server.
tomfra wrote:Also, if I do install it in the cgi-bin folder, will such script have access to files outside of the cgi-bin folder (in the public_html root folder and subdirectories)?
That depends on your setup, your webserver can be configured to run your CGI apps/scripts under your username or it may be configured to run under the 'nobody' user (or some such similar user) in either case access restrictions will be decided upon by you filesystem permissions.

As this post does not directly concern PHP code as such, it would have been better suited in the 'Webserver' section.