Instalar nginx en Debian con soporte PHP5 y MySQL

Primero instalaremos el servidor MySQL.

sudo apt-get install mysql-server mysql-client

Al terminar de instalar los paquetes nos pedira la clave para el usuario root.

A continuacion instalaremos php5 con todos los paquetes que queramos, en este caso solo el soporte para mysql, el cli y el cgi. Tambien instalaremos el paquete spawn-fcgi de lighttpd para el cgi.

sudo apt-get install php5 php5-cli php5-cgi spawn-fcgi

Solo nos queda por instalar nginx.

sudo apt-get install nginx

Una vez instalado arrancamos spawn-fcgi en el puerto 9000 o cualquier otro que queramos.

sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

Editamos la configuracion del sitio por defecto (/etc/nginx/sites-enabled/default), la configuracion mas simple para php seria esta.

server {
    listen        80;
    server_name   nginx.org  www.nginx.org;
    root          /data/www;

    location / {
        index     index.html  index.php;
    }

    location ~* .(gif|jpg|png)$ {
        expires   30d;
    }

    location ~ .php$ {
        fastcgi_pass   localhost:9000;
        fastcgi_param  SCRIPT_FILENAME
                       $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Creamos un fichero de prueba en /data/www que se llame index.php con el siguiente contenido

<?php
        php_info();
?>

Reiniciamos el servidor.

sudo /etc/init.d/nginx restart

Ya deberiamos poder ver la informaccion de php accediendo a localhost desde el navegador.

Para que se inicie spawn-fcgi cada vez que reiniciemos el servidor tenemos que escribir esta linea antes de exit 0 en el fichero /etc/rc.local

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>