Versiuni multiple de PHP pe Sabayon Linux

Postat la Sat 01 February 2014 in proiecte

Am folosit doar aplicatii diponibile in distributia standard.

Pentru instalare am folosit package managerul equo pentru pachetele binare si emerge pentru compilarea pachetelor din surse:

Am instalat apache2 si modulul fcgid pentru rularea php.

equo install app-admin/apache-tools-2.2.25 www-apache/mod_fcgid-2.3.9 www-servers/apache-2.2.25

Am instalat din pachete binare versiunile 5.3.28 si 5.4.24 la PHP:

equo install dev-lang/php-5.3.28-r1 dev-lang/php-5.4.24

Pentru activarea mod_php si mod-fcgid am adaugat in fisierul /etc/conf.d/apache2 in linia de optiuni urmatorii parametrii:

"-D PHP5 -D FCGID"

Folosind functia eselect disponibila am setat versiunea de php ce o voi folosi cu php in modul clasic

root@cristi ~ # eselect php list apache2
  [1]   php5.3
  [2]   php5.4 *

Versiunea poate fi setata cu comanda

root@cristi ~ # eselect php set apache2 2

Similar pute seta versiunea pe care o va folosi consola php

root@cristi ~ # eselect php list cli
  [1]   php5.3
  [2]   php5.4 *

Am repornit serverul apache

systemd restart apache2

Am creat micul fisier pentru afisarea modulelor php , info.php in /var/www/localhost

<?php

phpinfo();

?>

Si testatam functionarea serverului apache cu PHP 5.4 ruland in modul clasic la adresa http://127.0.0.1/info.php

Versiunile de PHP 5.5 si 5.6 nu se regasesc inca intre pachetele binare si au fost instalate din surse cu ajutorul aplicatiei emerge iar PHP 5.6 find inca in varianta alpha este blocat default la instalare de catre echipa Gentoo. Pentru activare am adaugat in fisierul /etc/portage/package.unmask/00-sabayon.package.unmask linia:

=dev-lang/php-5.6.0_alpha1

Compilarea am executat-o cu comenzile:

emerge =dev-lang/php-5.5.8
emerge =dev-lang/php-5.6.0_alpha1

fiecare compilare durand 5-10 min pe sistemul meu. (dependintele necesare se compileaza de asemeneea)

In lista de versiuni php se va modifica:

# eselect php list apache2
  [1]   php5.3
  [2]   php5.4 *
  [3]   php5.5
  [4]   php5.6

NOTA: fiecare versiune de PHP stocheaza separat executabilele si fiserele de configurare ceea ce permite o configurare mai precisa conform nevoilor in fiecare caz.

Am creat cateva domenii virtuale locale pe care le voi folosi la testare si le-am introdus in /etc/hosts

127.0.0.1 php53.local php54.local php55.local php56.local

Am creat 2 foldere in /var/www

# mkdir /var/www/bin
# mkdir /var/www/phptest  - ca folder de proiecte

Am modificat ca proprietar al celor 2 folder userul cristi.

# chown cristi:cristi /var/www/bin
# chown cristi:cristi /var/www/phptest

Am creat fisiere de configurare a domeniilor in /etc/apache2/vhosts.d:

php53-local.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<VirtualHost 127.0.0.1:80>
    ServerName php53.local
    DocumentRoot /var/www/phptest
   SuexecUserGroup cristi cristi
    <Directory "/var/www/phptest">
    AddHandler fcgid-script .php
        FCGIWrapper /var/www/bin/php5.3.fcgi .php
        Order allow,deny
        Allow from all
    AllowOverride All
      Options Indexes IncludesNOEXEC FollowSymLinks ExecCGI
    </Directory>
</VirtualHost>

php54-local.conf:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<VirtualHost 127.0.0.1:80>
    ServerName php54.local
    DocumentRoot /var/www/phptest
   SuexecUserGroup cristi cristi
    <Directory "/var/www/phptest">
    AddHandler fcgid-script .php
        FCGIWrapper /var/www/bin/php5.4.fcgi .php
        Order allow,deny
        Allow from all
    AllowOverride All
      Options Indexes IncludesNOEXEC FollowSymLinks ExecCGI
    </Directory>
</VirtualHost>

php55-local.conf:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<VirtualHost 127.0.0.1:80>
    ServerName php55.local
    DocumentRoot /var/www/phptest
   SuexecUserGroup cristi cristi
    <Directory "/var/www/phptest">
    AddHandler fcgid-script .php
        FCGIWrapper /var/www/bin/php5.5.fcgi .php
        Order allow,deny
        Allow from all
    AllowOverride All
      Options Indexes IncludesNOEXEC FollowSymLinks ExecCGI
    </Directory>
</VirtualHost>

php56-local.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<VirtualHost 127.0.0.1:80>
    ServerName php56.local
    DocumentRoot /var/www/phptest
   SuexecUserGroup cristi cristi
    <Directory "/var/www/phptest">
    AddHandler fcgid-script .php
        FCGIWrapper /var/www/bin/php5.6.fcgi .php
        Order allow,deny
        Allow from all
    AllowOverride All
      Options Indexes IncludesNOEXEC FollowSymLinks ExecCGI
    </Directory>
</VirtualHost>

In folderul /var/www/bin am creat scripturi pentru rularea fisierelor php via fcgid

root@cristi /var/www/bin #  ll
total 16K
-rwxr-xr-x 1 cristi cristi 205 Jan 29 23:06 php5.3.fcgi*
-rwxr-xr-x 1 cristi cristi 205 Jan 29 23:06 php5.4.fcgi*
-rwxr-xr-x 1 cristi cristi 205 Dec 22 21:35 php5.5.fcgi*
-rwxr-xr-x 1 cristi cristi 205 Jan 29 23:53 php5.6.fcgi*

php5.3.fcgi:

1
2
3
4
5
6
7
#!/bin/sh
PHPRC=/etc/php/cgi-php5.3/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
# See http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
export PHP_FCGI_CHILDREN=0
exec /usr/lib64/php5.3/bin/php-cgi

php5.4.fcgi:

1
2
3
4
5
6
7
#!/bin/sh
PHPRC=/etc/php/cgi-php5.4/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
# See http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
export PHP_FCGI_CHILDREN=0
exec /usr/lib64/php5.4/bin/php-cgi

php5.5.fcgi:

1
2
3
4
5
6
7
#!/bin/sh
PHPRC=/etc/php/cgi-php5.5/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
# See http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
export PHP_FCGI_CHILDREN=0
exec /usr/lib64/php5.5/bin/php-cgi

php5.6.fcgi:

1
2
3
4
5
6
7
#!/bin/sh
PHPRC=/etc/php/cgi-php5.6/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
# See http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
export PHP_FCGI_CHILDREN=0
exec /usr/lib64/php5.6/bin/php-cgi

Repornim serverul apache:

systemd restart apache2

si creem un fisier info.php in folderul /var/www/phptest.

Acum putem testa domeniile pentru a verifica configuratiile domeniilor:

http://php53.local

http://php54.local

http://php55.local

http://php56.local

NOTA: Nici un animal nu a fost ranit in acest experiment.