• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Mikey Boldt

What am I doing?

  • Home
  • About Mikey
  • Contact

htaccess

Configure .htaccess. to use FastCGI for PHP

2012-12-10 by Mikey Boldt Leave a Comment

Introduction

I had a request to use FastCGI for PHP handling on a wordpress site, to fix permissions issues. That is, FastCGI runs the PHP scripts as the owner instead of the apache user. This plays more nicely with e.g. file uploads and script-generated files. Here’s a link for More info on PHP handlers.

The configuration was a little tricky, and I didn’t find a single site that laid it all out easily. Here are the steps:

Ensure mod_fcgid is loaded

Check that this line appears in httpd.conf:

LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so

Create a wrapper script

I don’t fully grok it, but mod_fcgid must run the CGI scripts using suexec. suexec expects everything it runs to be inside the its document root. This document root can be found by running the command (as root):

/usr/sbin/suexec -V

and looking for the value of AP_DOC_ROOT. Mine is /var/www.

So, we make a wrapper script for the PHP CGI handler underneath the document root. We can set other relevant variables in there. Here’s an example, which I put in /var/www/cgi-bin/php-fastcgi:

#!/bin/sh
PHPRC=/etc/
export PHPRC # php.ini directory.
export PHP_FCGI_MAX_REQUESTS=5000 # Num requests before restarting process.
export PHP_FCGI_CHILDREN=8
exec /usr/bin/php-cgi # Call the regular PHP handler.

Update .htaccess settings

Now, we tell the web server ot run PHP scripts using fcgid:

AddHandler fcgid-script .php
Options +ExecCGI
FcgidWrapper /var/www/cgi-bin/php-fcgi .php

I believe this can also be done in httpd.conf, but this was my solution.

Done

We can see that it worked by looking at the “Server API” line in phpinfo(); it should have changed from e.g. “Apache 2.0 Handler” to “CGI/FastCGI”.

Share this:

  • Email
  • Facebook
  • Twitter

Filed Under: Tech Tagged With: apache, fastcgi, htaccess, mod_fcgid, php

Primary Sidebar

Categories

  • Orthodoxy
  • Tech
  • Uncategorized

Tags

4331 abfh android apache bible bluetooth cull dropbox dropsync emacs email ezpdf reader fastcgi geeqie gnome gnu global gnus htaccess key bindings keyboard linux mac macbook mod_fcgid msoffice nexus 7 notmuch orgmode papers pdf photo php politics prayer proced processes software sopa top ubuntu upgrade virtualbox vnc xfce xmonad

Archives

  • February 2016
  • January 2016
  • September 2014
  • December 2013
  • November 2013
  • December 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • January 2012
  • December 2011
  • November 2011

Subscribe

  • RSS - Posts
  • RSS - Comments

Copyright © 2021 · Mikey Boldt Theme on Genesis Framework · WordPress · Log in

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.