Après analyse, la seule façon de pouvoir lancer 2 PHP différents est d’utiliser 2 PHP différents compilés en CGI. (En effet, la directive LoadModule pour charger la librairie PHP, ne peut être integré à un VirtualHost)
Partant de ce constat, il faut noter que les directives php_admin_value et php_admin_flag, qui permettent de modifier les valeurs par défaut de PHP (fichier php.ini) ne sont valables que lorsque PHP est utilisé en module. Il est donc exclu de les utiliser en CGI.
Conclusion : Il est possible techniquement de lancer 2 PHP compilés différemment, mais chaque PHP aura un php.ini défini et non modifiable par des directives.
Cela signifie notamment que tout ce qui concerne :
est non personnalisable par utilisateur dans la solution CGI. En d’autres termes, tous les utilisateurs mutualisés auront soit le php.ini (version toutes fonctions), soit le php.ini (version restreinte)
On doit patcher Apache pour qu’on puisse ajouter l’option –phpsuexec lors de la configuration :
cd /usr/local/src/apache_1.3.27/
wget ftp://ftp.ovh.net/made-in-ovh/maj-ovh/mod_gzip.c.gz -O mod_gzip.c.gz
wget http://www.localhost.nl/patches/apache_1.3.27-php-suexec-patch -O
apache_1.3.27-php-suexec-patch
wget http://www.localhost.nl/patches/apache_1.3.27-nouids -O
apache_1.3.27-nouids
patch -p1 <
src/apache_1.3.27-php-suexec-patch
patch -p1 <
src/apache_1.3.27-nouids
Remarque :
Le patch apache_1.3.27-php-suexec-patch modifie notamment le
fichier :
/usr/local/src/apache_1.3.27/src/modules/standard/mod_cgi.c
en y ajoutant les lignes :
#ifdef INCLUDEPHP
#define PHP3HANDLER
"/usr/local/bin/php3.cgi"
#define PHP4HANDLER
"/usr/local/bin/php4.cgi"
#define PHP3 3
#define PHP4 4
#define PHP3TYPE
"application/x-httpd-php3"
#define PHP4TYPE
"application/x-httpd-php"
#endif
Pour rajouter un CGI supplémentaire (ou renommer le handler
utilisé dans httpd.conf, il suffit de rajouter ou modifier les lignes suivant
le modèle existant )
Ex : Lignes a modifier (pour la version 1.3.27 de
Apache) pour ajouter le CGI PHP0.cgi :
/usr/local/src/apache_1.3.27/src/modules/standard/mod_cgi.c
82 - ..
#ifdef INCLUDEPHP
#define PHP3HANDLER
"/usr/local/bin/php3.cgi"
#define PHP4HANDLER
"/usr/local/bin/php4.cgi"
#define PHP0HANDLER
"/usr/local/bin/php0.cgi"
#define PHP3 3
#define PHP4 4
#define PHP0 4
#define PHP3TYPE "application/x-httpd-php3"
#define PHP4TYPE "application/x-httpd-php"
#define PHP0TYPE "application/x-httpd-php0"
#endif
Ligne 416 - …
#ifdef INCLUDEPHP
if
(r->handler)
{
if
(!strcmp(r->handler, PHP4TYPE))
{
cld.phptype = PHP4;
cld.phphandler
= PHP4HANDLER;
}
else if
(!strcmp(r->handler, PHP3TYPE))
{
cld.phptype = PHP3;
cld.phphandler = PHP3HANDLER;
}
else if (!strcmp(r->handler, PHP0TYPE))
{
cld.phptype = PHP4;
cld.phphandler = PHP0HANDLER;
}
else
{
cld.phptype = 0;
}
}
#endif
Ligne 660 - …
#ifdef INCLUDEPHP
{PHP3TYPE,
cgi_handler},
{PHP4TYPE,
cgi_handler},
{PHP0TYPE,
cgi_handler},
#endif
./configure
--with-layout=Apache --prefix=/usr/local/apache --enable-module=rewrite
--server-uid=apache --server-gid=apache --enable-suexec --enable-suexecphp
--suexec-docroot=/home --suexec-caller=apache --suexec-umask=077
--suexec-userdir=www --enable-module=so
make clean
make
make install
/usr/local/apache/bin/suexec -V
On vérifie les options du suexec nouvellement crée:
-D DOC_ROOT="/home"
-D
GID_MID=100
-D HTTPD_USER="apache"
-D LOG_EXEC="/usr/local/apache/logs/suexec_log"
-D
SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
-D SUEXEC_UMASK=077
-D
UID_MID=100
-D USERDIR_SUFFIX="www"
cd
/usr/local/php-4.3.2
./configure
--prefix=/usr/local/php-4.3.2 --with-config-file-path=/usr/local/php-4.3.2
--enable-discard-path --enable-sigchild --enable-magic-quotes
--enable-short-tags --with-exec-dir=/home/ --with-mysql=/usr/local/mysql
--with-kerberos --with-xml --enable-xslt
--with-xslt-sablot=/usr/local/sablotron --with-expat-dir=/usr/local/expat
--with-pgsql=/usr/local/pgsql --with-gd --with-zlib-dir=/usr
--with-jpeg-dir=/usr --with-ming=/usr/local/src/ming-0.2a --enable-ftp
make clean
make
make install
cp /usr/local/php-4.3.0/bin/php /usr/local/bin/php4.cgi
(Recompiler une deuxieme fois avec les options restreintes et reconstruire)
make
make install
cp /usr/local/php-4.3.0/bin/php /usr/local/bin/php3.cgi
Le fichier php.ini a changé d’emplacement (vérifier avec un phpinfo() au besoin après avoir lancé Apache)
cp /usr/local/lib/php.ini /usr/local/php-4.3.2/
mv /usr/local/lib/php.ini /usr/local/lib/php.ini_old
vi /usr/local/apache/conf/httpd.conf
Mettre en commentaire la librairie PHP :
#LoadModule php4_module libexec/libphp4.so
Remplacer :
<Directory /home/*/www>
AllowOverride FileInfo AuthConfig Indexes Limit Options
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
Par :
<Directory "/home/*/www">
Options +ExecCGI +Indexes +FollowSymLinks
Order allow,deny
Allow from all
</Directory>
Ajouter :
# PHP4.3.2 : Fonctionnalités complètes
AddHandler application/x-httpd-php .php .php4 .php3
Ou
# PHP4.3.2 : Fonctionnalités RESTREINTES
AddHandler application/x-httpd-php3 .php .php4 .php3
Au besoin, indiquer aussi les user et groupe qui executeront les fichiers PHP (sinon apache, apache) :
User test
Group users
Supprimer tout les directives (sinon Apache ne redémarrera pas) :
php_admin_flag
php_admin_value
httpd stop
httpd start
tail
/usr/local/apache/logs/error_log
On vérifie
:
[Thu Jan 15
06:26:10 2004] [notice] Apache/1.3.27 (Unix) PHP-CGI/0.1b configured --
resuming normal operations
[Thu Jan 15 06:26:10 2004] [notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/bin/suexec)
[Thu Jan 15 06:26:10 2004] [notice] Accept mutex: sysvsem (Default: sysvsem)