Apache FastCGI / mod_fastcgi PHP Script

Use this script to run Apache 2.x with mod_fastcgi. Install Apache 22 from FreeBSD port or using source code. The script is tested under FreeBSD and Debian / RHEL / CentOS Linux.

How do I use script?

Download the script

Put in cgi-bin directory as php.cgi

Set permission

Configure httpd.conf as follows for mod_fastcgi:

<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        DocumentRoot "/websites/home/example.com/http"
        ServerName example.com
        ServerAlias www.example.com
        ErrorLog "/websites/home/example.com/logs/error.log"
        CustomLog "/websites/home/example.com/logs/access.log" common
        ScriptAlias /cgi-bin/ "/websites/home/example.com/cgi-bin/"
<Directory "/websites/home/example.com/http">
    Options -Indexes FollowSymLinks +ExecCGI
    AllowOverride AuthConfig FileInfo
    AddHandler php5-fastcgi .php
    Action php5-fastcgi /cgi-bin/php.cgi
    Order allow,deny
    Allow from all
<Directory "/websites/home/example.com/cgi-bin">
  AllowOverride None
  Options None
  Order allow,deny
  Allow from all
#SuExecUserGroup exampleUser exampleGroup

See Red hat / CentOS Linux mod_fastcgi and FreeBSD mod_fastcgi tutorial for detailed information.;

Sample mod_fastcgi PHP script

# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/>
# This script is licensed under GNU GPL version 2.0 or above
# Comment/suggestion: <vivek@nixCraft.com>
# http://bash.cyberciti.biz/misc-shell/linux-start-stop-restar-toracle-server/
# -------------------------------------------------------------------------
### Set PATH ###
### no editing below ###
exec $PHP_CGI
Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics:
CategoryList of Unix and Linux commands
File Management cat
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Quoc Sep 25, 2011 @ 2:13

    try to turn off mod_cgi if it still work. This is the setting for mod_cgi, It’s does not use mod_fastcgi at all

  • Riadh Sep 27, 2010 @ 4:14

    I’ve read a dozen articles explaining how to set-up php5 with fast cgi without being able to make it work.
    Now that I’ve read yours, everything works perfectly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.