Posts Tagged: ‘cgi’

Installing Apache2 and PHP5 using mod_fcgid

November 25, 2009 Posted by admin

This howto will walk you through installing mod_fcgid on centos 5.3. By using fcgid you will notice a couple of benefits.
1.) Apache memory footprint is smaller because of not having to load the php modules
2.) You will have a single fcgid process
3.) You get the security benefits of running script using fcgid & suexec

You will have to enable the epl repository

yum install mod_fcgid

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.disable

modify

vi /etc/httpd/conf.d/fcgid.conf

I added some options to mine

LoadModule fcgid_module modules/mod_fcgid.so
# Use FastCGI to process .fcg .fcgi & .fpl scripts
# Don’t do this if mod_fastcgi is present, as it will try to do the same thing
<IfModule !mod_fastcgi.c>
AddHandler fcgid-script fcg fcgi fpl
# Where to look for the php.ini file?
DefaultInitEnv PHPRC        “/etc/php5/cgi”
# Maximum requests a process should handle before it is terminated
MaxRequestsPerProcess       1000
# Maximum number of PHP processes
MaxProcessCount             15
# Number of seconds of idle time before a php-cgi process is terminated
IPCCommTimeout              120
IdleTimeout                 120
BusyScanInterval            120
BusyTimeout                 300
DefaultInitEnv PHP_FCGI_CHILDREN     1
DefaultInitEnv PHP_FCGI_MAX_REQUESTS 1000
DefaultMaxClassProcessCount          8
DefaultMinClassProcessCount          4
ErrorScanInterval           3
IdleTimeout                 300
IdleScanInterval            120
OutputBufferSize            64
ProcessLifeTime             3600
SpawnScore                  1
SpawnScoreUpLimit           10
TerminationScore            2
ZombieScanInterval          3
SocketPath  /var/tmp/fcgi-ipc/
Action      application/x-httpd-php5    /php/php5.fcgi
AddType     application/x-httpd-php5    .php .php5
</IfModule>

# Sane place to put sockets and shared memory file
SocketPath run/mod_fcgid
SharememPath run/mod_fcgid/fcgid_shm

Then next create your virtual hosts

### VirtualHost TEST1.COM ###

<VirtualHost *:80>
ServerName www.test1.com
ServerAlias test1.com
ServerAdmin webmaster@test1.com
DocumentRoot /var/www/www.test1.com/web

SuexecUserGroup test1 test1
PHP_Fix_Pathinfo_Enable 1
IPCConnectTimeout 8
IPCCommTimeout 48
ScriptAlias /php/ “/var/www/www.test1/php/”

Options ExecCGI
SetHandler fcgid-script
Order allow,deny
Allow from all

ServerSignature Off

</VirtualHost>

### VirtualHost TEST2.COM ###

<VirtualHost *:80>
ServerName www.test2.com
ServerAlias test2.com
ServerAdmin webmaster@test2.com
DocumentRoot /var/www/www.test2.com/web

SuexecUserGroup test2 test2
IPCConnectTimeout 8
IPCCommTimeout 48
PHP_Fix_Pathinfo_Enable 1
ScriptAlias /php/ “/var/www/www.blitzkrieg.net/php/”

Options ExecCGI
SetHandler fcgid-script
Order allow,deny
Allow from all

ServerSignature Off

</VirtualHost>

Next create the virtual Host directories

mkdir -p /var/www/www.test1.com/web
mkdir -p /var/www/www.test1.com/php

mkdir -p /var/www/www.test2.com/web
mkdir -p /var/www/www.test2.com/php

Next add the users

useradd -d /var/www/www.test1.com test1
useradd -d /var/www/www.test2.com test2

Next set the permissions

chown -R test1:test1 /var/www/www.test1.com
chown -R test2:test2 /var/www/www.test2.com

next create a php script in the wed directory of you nexly created sites.

vi /var/www/www.test1.com/web/index.php

<?php

echo “Hello World”;

?>