Mod_fcgid è un modulo di Apache che permette l’esecuzione di applicazioni esterne che creano documenti web come output.
Utilizzare Php con mod_fcgid ha come conseguenza alcuni vantaggi rispetto al normale modo di eseguire Php su un server web, risulta infatti possibile eseguire versioni diverse di Php sullo stesso server e di utilizzare utenti diversi per l’esecuzione.
Inoltre mod_fcgid può essere eseguito su un server web Apache multi thread e garantisce quindi ottime prestazioni.
Vediamo quindi come installare mod_fcgid su un server Debian con Apache.
I pacchetti necessari sono php5-cgi, libapache2-mod-fcgid e apache2-mpm-worker.
Apache2-mpm-worker è il modulo multi processing multi thread per Apache, sostituisce apache2-mpm-prefork che è il modulo multi processing single thread richiesto da mod_php4 e mod_php5.
apt-get -u install php5-cgi libapache2-mod-fcgid apache2-mpm-worker
A questo punto è possibile eliminare mod_php4 e mod_php5
a2dismod php4
a2dismod php5
Abilitare mod_actions e mod_fcgid
a2enmod actions
a2enmod fcgid
Aumentare il valore relativo al tempo massimo di esecuzioni per le applicazioni FCGI, per fare questo è necessario modificare il file /etc/apache2/mods-enabled/fcgid.conf aggiungendo la direttivaIPCCommTimeout
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
SocketPath /var/lib/apache2/fcgid/sock
IPCCommTimeout 60
#IPCConnectTimeout 3
</IfModule>
Creare il file /etc/apache2/conf.d/php-fcgid.conf con il seguente contenuto.
<IfModule !mod_php4.c>
<IfModule !mod_php4_filter.c>
<IfModule !mod_php5.c>
<IfModule !mod_php5_filter.c>
<IfModule !mod_php5_hooks.c>
<IfModule mod_actions.c>
<IfModule mod_alias.c>
<IfModule mod_mime.c>
<IfModule mod_fcgid.c>
# Path to php.ini – defaults to /etc/phpX/cgi
DefaultInitEnv PHPRC=/etc/php5/cgi
# Number of PHP childs that will be launched. Leave undefined to let PHP decide.
#DefaultInitEnv PHP_FCGI_CHILDREN 3
# Maximum requests before a process is stopped and a new one is launched
#DefaultInitEnv PHP_FCGI_MAX_REQUESTS 5000
# Define a new handler “php-fcgi” for “.php” files, plus the action that must follow
AddHandler php-fcgi .php
Action php-fcgi /fcgi-bin/php-fcgi-wrapper
# Define the MIME-Type for “.php” files
AddType application/x-httpd-php .php
# Define alias “/fcgi-bin/”. The action above is using this value, which means that
# you could run another “php5-cgi” command by just changing this alias
Alias /fcgi-bin/ /var/www/fcgi-bin.d/php5-default/
# Turn on the fcgid-script handler for all files within the alias “/fcgi-bin/”
<Location /fcgi-bin/>
SetHandler fcgid-script
Options +ExecCGI
</Location>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
</IfModule>
A questo punto è possibile creare la directory specificata nella direttiva alias nel file di configurazione e creare un link simbolico a php5-cgi
mkdir /var/www/fcgi-bin.d/php5-default
ln -s /usr/bin/php5-cgi /var/www/fcgi-bin.d/php5-default/php-fcgi-wrapper
Riavviare Apache
/etc/init.d/apache2 restart