Translate

lunes, 22 de agosto de 2011

MULTIPLES VERSIONES DE PHP EN UN SOLO APACHE

Instalar PHP5.2 y PHP5.3 (REVISION)

1°.- Instalar APACHE2 y PHP5.3

apt-get install apache2 php5 php5-dev libapache2-mod-php5

2°.- Instalar PHP5.2

gunzip php-5.2.17.tar.gz
tar -xf php-5.2.17.tar
cd php-5.2.17/

Install the build tools to manually compile PHP-5.2.

apt-get install libxml2-dev libmysqlclient-dev libcurl4-gnutls-dev libpng12-dev libjpeg62-dev postgresql-server-dev-8.4

Then configure and install PHP-5-2 to /opt/php5.2

./configure --prefix=/etc/php52 --with-config-file-path=/usr/local/src/ServerWeb/php-5.2.17 --with-mysqli --with-mysql --with-curl --with-gd --with-jpeg-dir --enable-cli --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect --with-pgsql

make
make install

3°.- Probar funcionamiento de los PHP

Escribimos este archivo testphp.php en el PATH /var/www,  lo siguiente:

-----------------------------------------
testphp.php

echo phpinfo()
-----------------------------------------

Para PHP5.2

/etc/php52/bin/php /var/www/testphp.php

Para PHP5.3

root@Migracion-2:/# php /var/www/testphp.php

Si nos da la info de PHP de cada versión estamos en buen camino.

4.- Instalar el libapache2-mod-fastcgi

Este paquete no esta en el repositorio de Debian 6 por lo que debemos bajarlo desde:

http://packages.debian.org/squeeze/libapache2-mod-fastcgi

y luego instalarlo manualmente

dpkg --install libapache2-mod-fastcgi_2.4.6-1_i386.deb o libapache2-mod-fastcgi_2.4.6-1_amd64.deb 

dependiendo de la estructura que tengamos en nuestro servidor.

5.- Activar modulos en Apache

a2enmod cgi
a2enmod fastcgi
a2enmod actions

6.- Crear archivo CGI

Creamos el archivo php52-cgi dentro del path /usr/lib/cgi-bin

-----------------------------------------
php52-cgi

#!/bin/bash

PHPRC="/etc/php52"
export PHPRC

PHP_FCGI_CHILDREN=4
export PHP_FCGI_CHILDREN

PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS

exec /etc/php52/bin/php-cgi
-----------------------------------------

le damos permisos de ejecución:

chmod +x /usr/lib/cgi-bin/php52-cgi

7.- Copiar el PHP.INI-RECOMMENDED

Dentro del PATH de archivos para instalar copiamos de la siguiente forma

cp /usr/local/src/ServerWeb/php-5.2.17php.ini-recommended /etc/php52/lib/php.ini

PATH de archivos para instalar
/usr/local/src/ServerWeb/php-5.2.17

PATH donde se instalo el PHP5.2
/etc/php52/

8.- Crear archivo php52.conf

El archivo de configuración para apache2 debe ser creado dentro de /etc/apache2, con la siguiente estructura:

---------------------------------------------------------------
php52.conf

#include for virtual hosts that need to run php-5,2

SetHandler applications/x-httpd-php5
<\FilesMatch>
ScriptAlias /php52-cgi /usr/lib/cgi-bin/php52-cgi
Action applications/x-httpd-php5 /php52-cgi
AddHandler applications/x-httpd-php5 .php
---------------------------------------------------------------


9.- Testeo del Funcionamiento

En el archivo /etc/hosts escribimos:

127.0.0.1 php52.localhost php53.localhost

Luego configuramos los VirtualHost dentro de PATH: /etc/apache2/sites-available de la siguiente forma:

Editamos el primer archivo que hace referencia al PHP5.2


-------------------------------------------------------

php52

ServerAdmin webmaster@localhost
DocumentRoot /var/www
ServerName php52.localhost
#Include php5.2
Include php52.conf

ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog /var/log/apache2/access.log combined
----------------------------------------------------------

y luego creamos un link soft en /etc/apache2/sites-enable

ln -s /etc/apache2/sites-available/php52 php52

Editamos el segundo archivo para PHP53

-----------------------------------------------------------------
php53

ServerAdmin webmaster@localhost
DocumentRoot /var/www
ServerName php53.localhost

ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
----------------------------------------------------------------

y luego creamos un link soft en /etc/apache2/sites-enable

ln -s /etc/apache2/sites-available/php53 php53

Reiniciamos el apache

service apache2 restart

Luego vamos al navegador local de server y probamos haciendo

php52.localhost/testphp.php
php53.localhost/testphp.php


Lo que debemos ver es la configuración de cada PHP instalado.

No hay comentarios: