Configurando Lighttpd para soporte PHP con FastCGI

0 Comments

La ventaja de rapidez y desempeño de FastCGI es dada gracias a que en lugar de crear un nuevo proceso por cada peticion del cliente, FastCGI utiliza el mismo proceso persistente una y otra vez, y de esta manera atiende miles de clientes a lo largo del tiempo de vida de su ejecucion.

Soporte FastCGI de PHP

Antes de empezar la instalacion del interprete de hypertexto PHP, debemos de asegurarnos que nuestro sistema Linux soporte fastcgi.

Para lo cual tecleamos el siguiente comando:

root@WebServer01:~# php -v
PHP 5.2.6-3ubuntu4.6 with Suhosin-Patch 0.9.6.2 (cli) (built: Sep 16 2010 19:51:25)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Tambien, tenemos la opcion del siguiente comando;

root@WebServer01:~# php-cgi -v
The program 'php-cgi' is currently not installed.  You can install it by typing:
apt-get install php5-cgi
-bash: php-cgi: command not found

Como pueden ver, el soporte CGI no esta activo. En esta oportunidad el servidor es un Linux Ubuntu, y tal como dice el comando, lo instalamos tecleando:

root@WebServer01:~# apt-get install php5-cgi
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Suggested packages:
 php-pear
The following NEW packages will be installed:
 php5-cgi
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 5100kB of archives.
After this operation, 11.4MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com jaunty-updates/main php5-cgi 5.2.6.dfsg.1-3ubuntu4.6 [5100kB]
Fetched 5100kB in 8s (603kB/s)                                                        
Selecting previously deselected package php5-cgi.
(Reading database ... 52984 files and directories currently installed.)
Unpacking php5-cgi (from .../php5-cgi_5.2.6.dfsg.1-3ubuntu4.6_amd64.deb) ...
Processing triggers for man-db ...
Setting up php5-cgi (5.2.6.dfsg.1-3ubuntu4.6) ...

Creating config file /etc/php5/cgi/php.ini with new version

Es necesario verificar el soporte CGI, asi que volvemos a teclear;

root@WebServer01:~# php-cgi -v
PHP 5.2.6-3ubuntu4.6 with Suhosin-Patch 0.9.6.2 (cgi-fcgi) (built: Sep 16 2010 19:48:27)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Buscamos la ruta para los binarios php-cgi :

root@WebServer01:~# which php-cgi
/usr/bin/php-cgi

Agregar Soporte PHP-CGI a Lighty

Ya que contamos con soporte PHP completo en nuestro sistema Linux, es hora de configurarlo en lighttpd. Para lo cual editamos el archivo de configuracion /etc/lighttpd/lighttpd.conf, donde;

Buscamos la linea donde se carga el modulo mod_fastcgi, es aqui donde lifhttpd brinda la interfaz para los programas externos que requieren FastCGI.

server.modules              = (
"mod_access",
"mod_accesslog",
"mod_fastcgi",
"mod_rewrite",
"mod_auth"
)

Ahora, siempre en el archivo de configuracion agregamos las siguientes lineas;

fastcgi.server = ( “.php” => ((
“bin-path” => “/usr/bin/php-cgi”,
“socket” => “/tmp/php.socket”
)))

Guardamos la configuracion y reiniciamos el servidor web;

root@WebServer01:~# /etc/init.d/lighttpd restart

Listo, ahora nuestro servidor web podra interpretar y desplegar paginas dinamicas de PHP.

One Reply to “Configurando Lighttpd para soporte PHP con FastCGI”

Deja tus preguntas o comentarios