How to run PHP script in "cgi mode"?

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

How to run PHP script in "cgi mode"?

Post 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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

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

Post 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.
Post Reply