Buscar este blog

sábado, 8 de diciembre de 2012

Make PHP 5.3.6

Hola buenas, se que es de madrugada pero no queria compartir la experiencia que tengo ahorita en linux, al tratar de generar mi propio compilado de php 5.3.6, resulta que tenemos plesk panel instalado y corriendo php 5.2, el cual fue un downgrade que hizo un amigo mio para poder correr zend optimizer, el cual es requerido por unas sitios web que tenemos alojados alli; regresando al asunto, encontre un articulo donde podia montar varias versiones de php para un determinado cliente como es este caso donde me toca trabajar con moodle en un dominio, y sin embargo la version 2.3 de moodle requiere si o si php 5.3 por cuestiones importantes ya que esta version soporta llamada dinamica a funciones de clases estaticas, mientras que versiones anteriores no soportan esta caracteristicas, entonces ahora me encuentro compilando mi version de php 5.3 que voy a usar para este nuevo dominio con plesk panel. A continuacion escribire la liste de comandos que usé, mas algunas enlaces de referencias que me fueron de mucha ayuda para resolver este reto. Saludos. Seguire actualizando este post :)

Two PHP versions linux Plesk HOWTO

Few days ago i was exchanging emails with Parallels support. I was asking them to help me to setup two php versions on linux plesk server. After few emails they answeared me that it is not possible. It didn't help when i told them that i was using fastcgi on my own hosting server and that i was having 3 php versions configurable per customer. Nop... Their answear was 
As of now there is no option available in the linux, where you can choose php as per the customers.
Hope you are clear now. If you have any further help, feel free to get back to us. We would be glad to assist you further.
And, there i was, left helpless, without possibility to finish migration from my old hosting server to our new and shiny Plesk. I needed newer php version because php provided by my linux distro is 5.1.
So, i logged in to Plesk server and spend around 20 minutes planning how to intercept Plesk calls. And it is done.
For this to work you have to have php running as fastcgi (it is most secure way, so i assume that everyone is running php as fastcgi)
Here it goes:

1. ssh to your plesk server, download php source, unpack it and configure it
ssh yourserver -l root cd /usr/local/src mkdir php540 cd php540 wget http://www.php.net/get/php-5.4.0.tar.gz/from/at2.php.net/mirror tar xzvf php-5.4.0.tar.gz cd php-5.4.0
NOTICE: you HAVE TO USE PREFIX switch in order to have your new php installed inside one directory, for example:

./configure '--with-libdir=lib64' '--cache-file=../config.cache' '--prefix=/usr/local/php536-cgi' '--with-config-file-path=/usr/local/php536-cgi/etc' '--disable-debug' '--with-pic' '--disable-rpath' '--with-bz2' '--with-curl' '--with-freetype-dir=/usr/local/php536-cgi' '--with-png-dir=/usr/local/php536-cgi' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr/local/php536-cgi' '--with-openssl' '--with-pspell' '--with-pcre-regex' '--with-zlib' '--enable-exif' '--enable-ftp' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-wddx' '--with-kerberos' '--with-unixODBC=/usr' '--enable-shmop' '--enable-calendar' '--without-sqlite3' '--with-libxml-dir=/usr/local/php536-cgi' '--enable-pcntl' '--with-imap' '--with-imap-ssl' '--enable-mbstring' '--enable-mbregex' '--with-gd' '--enable-bcmath' '--with-xmlrpc' '--with-ldap' '--with-ldap-sasl' '--with-mysql=/usr' '--with-mysqli' '--with-snmp' '--enable-soap' '--with-xsl' '--enable-xmlreader' '--enable-xmlwriter' '--enable-pdo' '--with-pdo-mysql' '--with-pdo-pgsql' '--with-pear=/usr/local/php536-cgi/pear' '--with-mcrypt' '--enable-intl' '--without-pdo-sqlite' '--with-config-file-scan-dir=/usr/local/php536-cgi/php.d' '--enable-zip'
As you can see, my prefix was /usr/local/php536-cgi/
Choosing a prefix is a MUST because that way your new php installation will not interfere with older php used by plesk.

2. compile your php
3. install your new php
make install
4. create php wrapper
for example, let's say that you have a customer blabla.com that uses some newer php functions that don't exist in php 5.1. Let's call that customer blabla.com. For him we will tell apache to use our new php (5.4.0)
cd /var/www/vhosts/blabla.com/cgi-bin mkdir .cgi_wrapper cd .cgi_wrapper
now we will create new file and name it .phpwrapper
vi .phpwrapper
file content:
#!/bin/sh export PHPRC=/var/www/vhosts/blabla.com/etc/ export PHP_FCGI_CHILDREN=4 export PHP_FCGI_MAX_REQUESTS=1000 exec /usr/local/php540-cgi/bin/php-cgi
let's strengthen our new files and dirs permissions and privileges:

cd /var/www/vhosts/blabla.com/cgi-bin chmod 101 .cgi_wrapper chmod 500 .cgi_wrapper/.phpwrapper chown blabla.com:psacln .cgi_wrapper -R chattr -R +i .cgi_wrapper

5. make apache aware of our wrapper
plesk offers a functionality of changing httpd setup per host. we will use that functionality to tell apache that for blabla.com it needs to use our new wrapper, instead of one provided by plesk:
cd /var/www/vhosts/blabla.com/conf
we will create file named vhost.conf
vi vhost.conf
file content:
RemoveHandler fcgid-script AddHandler fcgid-script .php SetHandler fcgid-script FCGIWrapper /var/www/vhosts/blabla.com/cgi-bin/.cgi_wrapper/.phpwrapper .php Options +ExecCGI allow from all
So, we have told apache not to use plesk php wrapper (RemoveHandler fcgid-script) and instead of that we have created a new handler for php files. When executing php files on blabla.com domain apache will call our wrapper and use new php that we installed

6. we need to reconfigure blabla.com domain
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain blabla.com
7. and restart apache
/etc/init.d/httpd restart
That's it. For every domain that needs some extra functions provided only in php versions newer than one provided with your plesk distro you can do steps 4,5,6 and 7 (replace blabla.com with your customer domain name) and that's all.

Adicional: A veces podemos necesitar instalar este paquete yum-install libtool-ltdl-devel