php as cgi

Place to discuss Fedora and/or Red Hat

Postby Stryker » Wed Apr 06, 2005 3:46 am

I figured I'd post back once I was comfortable with how it was working.

So this is what I do when I want to run PHP as CGI:

First I need to compile PHP with --enable-force-cgi-redirect so that it cannot be exploited by accessing the cgi-bin/php.cgi file directly from a browser.

./configure --enable-force-cgi-redirect
make

Now I had php installed before this. I did NOT want to do a make install, so I got the php binary from the compile and copied it to my cgi-bin directory as "php.cgi"

So, /cgi-bin/php.cgi points to the binary I just compiled.

Next, I just need to make my .htaccess file. Which is:

Code: Select all
AddHandler application/x-httpd-phpcgi .php .pcgi .php3 .phtml
Action application/x-httpd-phpcgi /cgi-bin/php.cgi


That's basically it. If you want to switch to php as an apache module, just delete the .htaccess file (or commend out the AddHandler line).

Of course to really take advantage of this, you'll need suexec installed (along with it's apache module).

It is (at least in my case) very important that the php.cgi file in cgi-bin is owned by the same user AND group as you are trying to execute it as (set with the user and group lines in httpd.conf)

if you have any problems, check apache's error log and the suexec log.
Stryker
scripter
scripter
 
Posts: 98
Joined: Thu Jan 23, 2003 8:50 pm

Previous

Return to Fedora/Red Hat

Who is online

Users browsing this forum: No registered users and 3 guests

cron