Compilation
(Page créée avec « == Présentation == Cette page a pour objet de décrire comment compiler PHP depuis les sources. == Passage de PHP 5 à PHP 7 == === Extensions disparues === ==== mssql =... ») |
|||
Ligne 260 : | Ligne 260 : | ||
Se rendre dans le dossier des sources et commencer la configuration de la compilation : | Se rendre dans le dossier des sources et commencer la configuration de la compilation : | ||
cd /local/builds/php-7.2.19 | cd /local/builds/php-7.2.19 | ||
+ | |||
+ | === configure === | ||
+ | Lancer la configuration de la compilation avec les options désirées : | ||
+ | <pre> | ||
+ | ./configure \ | ||
+ | --prefix=/local/php/php7 \ | ||
+ | --with-ldap \ | ||
+ | --enable-inline-optimization \ | ||
+ | --enable-debug=no \ | ||
+ | --enable-calendar \ | ||
+ | --enable-ftp \ | ||
+ | --enable-sysvsem \ | ||
+ | --enable-sysvshm \ | ||
+ | --disable-static \ | ||
+ | --enable-mysqlnd \ | ||
+ | --with-gettext \ | ||
+ | --with-pcre-regex \ | ||
+ | --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client64/lib \ | ||
+ | --enable-soap \ | ||
+ | --with-gd \ | ||
+ | --enable-zip \ | ||
+ | --with-bz2 \ | ||
+ | --with-zlib-dir \ | ||
+ | --with-mysqli \ | ||
+ | --with-libxml-dir=/usr/lib \ | ||
+ | --with-jpeg-dir=/usr/lib \ | ||
+ | --with-apxs2=/local/www/2.4.12/bin/apxs \ | ||
+ | --with-pdo-oci \ | ||
+ | --with-pdo-mysql \ | ||
+ | --enable-mbstring \ | ||
+ | --with-curl \ | ||
+ | --with-libdir=lib64 \ | ||
+ | --with-openssl | ||
+ | </pre> | ||
+ | |||
+ | <u>Exemple de retour sans erreur :</u> | ||
+ | <pre> | ||
+ | Generating files | ||
+ | configure: creating ./config.status | ||
+ | creating main/internal_functions.c | ||
+ | creating main/internal_functions_cli.c | ||
+ | +--------------------------------------------------------------------+ | ||
+ | | License: | | ||
+ | | This software is subject to the PHP License, available in this | | ||
+ | | distribution in the file LICENSE. By continuing this installation | | ||
+ | | process, you are bound by the terms of this license agreement. | | ||
+ | | If you do not agree with the terms of this license, you must abort | | ||
+ | | the installation process at this point. | | ||
+ | +--------------------------------------------------------------------+ | ||
+ | |||
+ | Thank you for using PHP. | ||
+ | |||
+ | config.status: creating php7.spec | ||
+ | config.status: creating main/build-defs.h | ||
+ | config.status: creating scripts/phpize | ||
+ | config.status: creating scripts/man1/phpize.1 | ||
+ | config.status: creating scripts/php-config | ||
+ | config.status: creating scripts/man1/php-config.1 | ||
+ | config.status: creating sapi/cli/php.1 | ||
+ | config.status: creating sapi/phpdbg/phpdbg.1 | ||
+ | config.status: creating sapi/cgi/php-cgi.1 | ||
+ | config.status: creating ext/phar/phar.1 | ||
+ | config.status: creating ext/phar/phar.phar.1 | ||
+ | config.status: creating main/php_config.h | ||
+ | config.status: executing default commands | ||
+ | </pre> | ||
+ | |||
+ | ==== Traitement des erreurs ==== | ||
+ | Lors du configure, des erreurs peuvent être détectées. Le script s'arrête alors avec un message. | ||
+ | |||
+ | <u>Exemple de message d'erreur :</u> | ||
+ | <pre> | ||
+ | checking for the location of libXpm... no | ||
+ | checking for FreeType 2... yes | ||
+ | checking whether to enable JIS-mapped Japanese font support in GD... no | ||
+ | If configure fails try --with-webp-dir=<DIR> | ||
+ | checking for jpeg_read_header in -ljpeg... yes | ||
+ | checking for png_write_image in -lpng... yes | ||
+ | If configure fails try --with-xpm-dir=<DIR> | ||
+ | configure: error: freetype-config not found. | ||
+ | </pre> | ||
+ | |||
+ | L'erreur ci-dessus porte sur le sous-module ''freetype'' du module ''gd'' de PHP. En effet, lançant la commande suivante : | ||
+ | ./configure --help | ||
+ | |||
+ | l'aide à la configuration de la compilation indique que l'option <code>--with-freetype-dir</code> attend un répertoire comme valeur : | ||
+ | <pre> | ||
+ | ... | ||
+ | --with-gd=DIR Include GD support. DIR is the GD library base | ||
+ | install directory BUNDLED | ||
+ | --with-webp-dir=DIR GD: Set the path to libwebp install prefix | ||
+ | --with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix | ||
+ | --with-png-dir=DIR GD: Set the path to libpng install prefix | ||
+ | --with-zlib-dir=DIR GD: Set the path to libz install prefix | ||
+ | --with-xpm-dir=DIR GD: Set the path to libXpm install prefix | ||
+ | --with-freetype-dir=DIR GD: Set the path to FreeType 2 install prefix | ||
+ | --enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support | ||
+ | ... | ||
+ | </pre> | ||
+ | |||
+ | Ce genre d'erreur est fréquente lors de la configuration de la compilation. Cela signifie qu'il manque des paquets nécessaire à la compilation. En l'occurrence, pour une une utilisation normale de ''freetype'' sur le serveur, seul le paquet '''freetype''' est nécessaire. Toutefois, en cas de compilation, il faut disposer des en-tête de développement en installant le paquet '''freetype-devel.''' : | ||
+ | yum install freetype-devel | ||
+ | |||
+ | La plupart de ces erreurs se traitent comme ceci : installer le paquet <code><module>-dev</code> ou <code><module>-devel</code>, où '''<module>''' correspond au module ayant généré une erreur. | ||
+ | |||
+ | Une fois l'installation réalisée, relancer la configuration de la compilation. | ||
+ | |||
+ | === make === | ||
+ | La configuration de la compilation étant précédemment réalisée, lancer simplement la compilation avec la commande suivante : | ||
+ | make | ||
+ | |||
+ | <u>Exemple de retour de compilation réussie :</u> | ||
+ | <pre> | ||
+ | Generating phar.php | ||
+ | Generating phar.phar | ||
+ | PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. | ||
+ | clicommand.inc | ||
+ | pharcommand.inc | ||
+ | directorytreeiterator.inc | ||
+ | directorygraphiterator.inc | ||
+ | invertedregexiterator.inc | ||
+ | phar.inc | ||
+ | |||
+ | Build complete. | ||
+ | Don't forget to run 'make test'. | ||
+ | </pre> | ||
+ | |||
+ | ==== En cas d'erreur ==== | ||
+ | Autant les erreurs de configuration de compilation sont facilement résolvables, autant les erreurs liées à l'étape de compilation sont particulières. Il faudra traiter au cas par cas et faire preuve d'un bon esprit d'analyse. | ||
+ | |||
+ | Par ailleurs, en cas d'erreur rencontrée lors de la compilation, il est recommandé de nettoyer le dossier des sources avant de relancer une configuration suivie d'une compilation avec la commande suivante : | ||
+ | make mostlyclean | ||
+ | make clean | ||
+ | make distclean | ||
+ | make maintainer-clean | ||
+ | |||
+ | === make install === | ||
+ | Une fois la compilation terminée, les fichiers résultants se trouvent dans le dossier de compilation. Pour installer les fichiers dans les différents dossiers nécessaires à l'utilisation de PHP, lancer la commande suivante : | ||
+ | make install | ||
+ | |||
+ | <u>Exemple de retour d'installation sans erreur :</u> | ||
+ | <pre> | ||
+ | Installing PHP SAPI module: apache2handler | ||
+ | /local/www/2.4.12/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /local/www/2.4.12/modules | ||
+ | /usr/lib64/apr-1/build/libtool --mode=install install libphp5.la /local/www/2.4.12/modules/ | ||
+ | libtool: install: install .libs/libphp5.so /local/www/2.4.12/modules/libphp5.so | ||
+ | libtool: install: install .libs/libphp5.lai /local/www/2.4.12/modules/libphp5.la | ||
+ | libtool: install: warning: remember to run `libtool --finish /local/builds/php-5.6.40/libs' | ||
+ | chmod 755 /local/www/2.4.12/modules/libphp5.so | ||
+ | [activating module `php5' in /local/www/2.4.12/conf/httpd.conf] | ||
+ | Installing shared extensions: /local/php/php5/lib64/extensions/no-debug-zts-20131226/ | ||
+ | Installing PHP CLI binary: /local/php/php5/bin/ | ||
+ | Installing PHP CLI man page: /local/php/php5/php/man/man1/ | ||
+ | Installing PHP CGI binary: /local/php/php5/bin/ | ||
+ | Installing PHP CGI man page: /local/php/php5/php/man/man1/ | ||
+ | Installing build environment: /local/php/php5/lib64/build/ | ||
+ | Installing header files: /local/php/php5/include/php/ | ||
+ | Installing helper programs: /local/php/php5/bin/ | ||
+ | program: phpize | ||
+ | program: php-config | ||
+ | Installing man pages: /local/php/php5/php/man/man1/ | ||
+ | page: phpize.1 | ||
+ | page: php-config.1 | ||
+ | Installing PEAR environment: /local/php/php5/lib64/php/ | ||
+ | [PEAR] Archive_Tar - installed: 1.4.4 | ||
+ | [PEAR] Console_Getopt - installed: 1.4.1 | ||
+ | [PEAR] Structures_Graph- installed: 1.1.1 | ||
+ | [PEAR] XML_Util - installed: 1.4.3 | ||
+ | [PEAR] PEAR - installed: 1.10.7 | ||
+ | Wrote PEAR system config file at: /local/php/php5/etc/pear.conf | ||
+ | You may want to add: /local/php/php5/lib64/php to your php.ini include_path | ||
+ | /local/builds/php-5.6.40/build/shtool install -c ext/phar/phar.phar /local/php/php5/bin | ||
+ | ln -s -f phar.phar /local/php/php5/bin/phar | ||
+ | Installing PDO headers: /local/php/php5/include/php/ext/pdo/ | ||
+ | </pre> | ||
+ | |||
+ | Il n'y a généralement pas d'erreur lors de cette étape. | ||
+ | |||
+ | == Compilation PHP 7.4.7 == | ||
+ | === Téléchargement de sources === | ||
+ | |||
+ | Créer le dossier d'installation cible : | ||
+ | mkdir -p /local/php/php-7.4.7 | ||
+ | |||
+ | Créer un lien symbolique pour pointer vers la version 7.4.7 : | ||
+ | ln -s php-7.4.7 /local/php/current | ||
+ | |||
+ | Créer le dossier de compilation, si inexistant : | ||
+ | mkdir -p /local/builds | ||
+ | |||
+ | Créer le dossier de téléchargement, si inexistant : | ||
+ | mkdir -p ~/downloads | ||
+ | |||
+ | Télécharger la version 5.6.40 avec la commande suivante : | ||
+ | wget -O ~/downloads/php-7.4.7.tar.gz https://www.php.net/distributions/php-7.4.7.tar.gz | ||
+ | |||
+ | La dézipper : | ||
+ | tar -xzf ~/downloads/php-7.4.7.tar.gz -C /local/builds/ | ||
+ | |||
+ | Se rendre dans le dossier des sources et commencer la configuration de la compilation : | ||
+ | cd /local/builds/php-7.4.7 | ||
+ | |||
+ | === Prérequis === | ||
+ | Au regard des options utilisées dans la section ''configure'' ci-dessous, les paquets suivants sont nécessaires : | ||
+ | <pre> | ||
+ | yum install zlib-devel | ||
+ | yum install bzip2-devel | ||
+ | yum install libcurl-devel | ||
+ | yum install libpng-devel | ||
+ | yum install libicu-devel libicu | ||
+ | yum install gcc-c++ libstdc++-devel | ||
+ | yum install openldap-devel cyrus-sasl cyrus-sasl-devel | ||
+ | yum install oniguruma-devel oniguruma | ||
+ | yum install libxml2-devel xz-devel | ||
+ | </pre> | ||
+ | |||
=== configure === | === configure === |
Version du 7 juillet 2020 à 07:15
Sommaire
Présentation
Cette page a pour objet de décrire comment compiler PHP depuis les sources.
Passage de PHP 5 à PHP 7
Extensions disparues
mssql
Selon la documentation officielle de l'extension mssql pour PHP, cette extension n'est plus disponible depuis la version 7.0.0.
L'alternative de cette extension sur un serveur Linux est détaillée dans la documentation des fonctions ODBC et DB2 (PDO_ODBC).
regex
Selon la documentation officielle de l'extension regex pour PHP, cette extension n'est plus disponible depuis la version 7.0.0.
L'alternative de cette extension est l'installation de l'extension PCRE. Elle est activée par défaut.
mcrypt
Selon la documentation officielle de l'extension mcrypt pour PHP, cette extension n'est plus disponible depuis la version 7.2.0.
L'alternative de cette extension est l'installation de l'extension OpenSSL.
Recompilation
Se rendre dans le dossier de la dernière compilation, par exemple /local/builds/php-7.3.4
, et faire un nettoyage préalable à la compilation :
make mostlyclean make clean make distclean make maintainer-clean
Lancer ensuite la compilation normalement.
Compilation dernière version de PHP 5
Téléchargement de sources
La dernière version officielle de PHP 5 est la 5.6.40 du 10 janvier 2019. Il n'y a donc plus de support sur la version 5 depuis cette date.
Créer le dossier d'installation cible :
mkdir /local/php/5.6.40
Créer un lien symbolique pour pointer vers la version 5.6.40 :
ln -s /local/php/5.6.40 /local/php/php5
Créer le dossier de compilation, si inexistant :
mkdir /local/builds
Créer le dossier de téléchargement, si inexistant :
mkdir ~/downloads
Télécharger la version 5.6.40 avec la commande suivante :
wget -O ~/downloads/php-5.6.40.tar.gz https://www.php.net/distributions/php-5.6.40.tar.gz
La dézipper :
tar -xzf ~/downloads/php-5.6.40.tar.gz -C /local/builds/
Se rendre dans le dossier des sources et commencer la configuration de la compilation :
cd /local/builds/php-5.6.40
configure
Lancer la configuration de la compilation avec les options désirées :
./configure \ --prefix=/local/php/php5 \ --with-ldap \ --enable-inline-optimization \ --enable-debug=no \ --enable-calendar \ --enable-ftp \ --enable-sysvsem \ --enable-sysvshm \ --disable-static \ --with-mysql \ --with-mssql=/usr/local/freetds \ --with-gettext \ --with-regex=system \ --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client64/lib \ --enable-soap \ --with-mcrypt=/usr/lib \ --with-gd \ --enable-zip \ --with-bz2 \ --with-zlib-dir \ --with-mysqli \ --with-libxml-dir=/usr/lib \ --with-jpeg-dir=/usr/lib \ --with-apxs2=/local/www/2.4.12/bin/apxs \ --with-pdo-oci \ --with-pdo-mysql \ --enable-mbstring \ --with-curl \ --with-libdir=lib64 \ --with-openssl
Exemple de retour sans erreur :
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
Traitement des erreurs
Lors du configure, des erreurs peuvent être détectées. Le script s'arrête alors avec un message.
Exemple de message d'erreur :
checking for the location of libXpm... no checking for FreeType 2... yes checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-webp-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes checking for png_write_image in -lpng... yes If configure fails try --with-xpm-dir=<DIR> configure: error: freetype-config not found.
L'erreur ci-dessus porte sur le sous-module freetype du module gd de PHP. En effet, lançant la commande suivante :
./configure --help
l'aide à la configuration de la compilation indique que l'option --with-freetype-dir
attend un répertoire comme valeur :
... --with-gd=DIR Include GD support. DIR is the GD library base install directory BUNDLED --with-webp-dir=DIR GD: Set the path to libwebp install prefix --with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix --with-png-dir=DIR GD: Set the path to libpng install prefix --with-zlib-dir=DIR GD: Set the path to libz install prefix --with-xpm-dir=DIR GD: Set the path to libXpm install prefix --with-freetype-dir=DIR GD: Set the path to FreeType 2 install prefix --enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support ...
Ce genre d'erreur est fréquente lors de la configuration de la compilation. Cela signifie qu'il manque des paquets nécessaire à la compilation. En l'occurrence, pour une une utilisation normale de freetype sur le serveur, seul le paquet freetype est nécessaire. Toutefois, en cas de compilation, il faut disposer des en-tête de développement en installant le paquet freetype-devel. :
yum install freetype-devel
La plupart de ces erreurs se traitent comme ceci : installer le paquet <module>-dev
ou <module>-devel
, où <module> correspond au module ayant généré une erreur.
Une fois l'installation réalisée, relancer la configuration de la compilation.
make
La configuration de la compilation étant précédemment réalisée, lancer simplement la compilation avec la commande suivante :
make
Exemple de retour de compilation réussie :
Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc pharcommand.inc directorytreeiterator.inc directorygraphiterator.inc invertedregexiterator.inc phar.inc Build complete. Don't forget to run 'make test'.
En cas d'erreur
Autant les erreurs de configuration de compilation sont facilement résolvables, autant les erreurs liées à l'étape de compilation sont particulières. Il faudra traiter au cas par cas et faire preuve d'un bon esprit d'analyse.
Par ailleurs, en cas d'erreur rencontrée lors de la compilation, il est recommandé de nettoyer le dossier des sources avant de relancer une configuration suivie d'une compilation avec la commande suivante :
make mostlyclean make clean make distclean make maintainer-clean
make install
Une fois la compilation terminée, les fichiers résultants se trouvent dans le dossier de compilation. Pour installer les fichiers dans les différents dossiers nécessaires à l'utilisation de PHP, lancer la commande suivante :
make install
Exemple de retour d'installation sans erreur :
Installing PHP SAPI module: apache2handler /local/www/2.4.12/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp7.la /local/www/2.4.12/modules /usr/lib64/apr-1/build/libtool --mode=install install libphp7.la /local/www/2.4.12/modules/ libtool: install: install .libs/libphp7.so /local/www/2.4.12/modules/libphp7.so libtool: install: install .libs/libphp7.lai /local/www/2.4.12/modules/libphp7.la libtool: install: warning: remember to run `libtool --finish /local/builds/php-7.2.19/libs' chmod 755 /local/www/2.4.12/modules/libphp7.so [activating module `php7' in /local/www/2.4.12/conf/httpd.conf] Installing shared extensions: /local/php/php7/lib64/extensions/no-debug-zts-20170718/ Installing PHP CLI binary: /local/php/php7/bin/ Installing PHP CLI man page: /local/php/php7/php/man/man1/ Installing phpdbg binary: /local/php/php7/bin/ Installing phpdbg man page: /local/php/php7/php/man/man1/ Installing PHP CGI binary: /local/php/php7/bin/ Installing PHP CGI man page: /local/php/php7/php/man/man1/ Installing build environment: /local/php/php7/lib64/build/ Installing header files: /local/php/php7/include/php/ Installing helper programs: /local/php/php7/bin/ program: phpize program: php-config Installing man pages: /local/php/php7/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /local/php/php7/lib64/php/ [PEAR] Archive_Tar - installed: 1.4.7 [PEAR] Console_Getopt - installed: 1.4.2 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.3 [PEAR] PEAR - installed: 1.10.9 Wrote PEAR system config file at: /local/php/php7/etc/pear.conf You may want to add: /local/php/php7/lib64/php to your php.ini include_path /local/builds/php-7.2.19/build/shtool install -c ext/phar/phar.phar /local/php/php7/bin ln -s -f phar.phar /local/php/php7/bin/phar Installing PDO headers: /local/php/php7/include/php/ext/pdo/
Il n'y a généralement pas d'erreur lors de cette étape.
Compilation PHP 7
Il faut adapter cette procédure en fonction de la version de PHP 7 désirée.
Dans cette procédure, c'est la version 7.2.19 qui est utilisée pour la démonstration.
Téléchargement de sources
Créer le dossier d'installation cible :
mkdir /local/php/7.2.19
Créer un lien symbolique pour pointer vers la version 5.6.40 :
ln -s /local/php/7.2.19 /local/php/php7
Créer le dossier de compilation, si inexistant :
mkdir /local/builds
Créer le dossier de téléchargement, si inexistant :
mkdir ~/downloads
Télécharger la version 5.6.40 avec la commande suivante :
wget -O ~/downloads/php-7.2.19.tar.gz https://www.php.net/distributions/php-7.2.19.tar.gz
La dézipper :
tar -xzf ~/downloads/php-7.2.19.tar.gz -C /local/builds/
Se rendre dans le dossier des sources et commencer la configuration de la compilation :
cd /local/builds/php-7.2.19
configure
Lancer la configuration de la compilation avec les options désirées :
./configure \ --prefix=/local/php/php7 \ --with-ldap \ --enable-inline-optimization \ --enable-debug=no \ --enable-calendar \ --enable-ftp \ --enable-sysvsem \ --enable-sysvshm \ --disable-static \ --enable-mysqlnd \ --with-gettext \ --with-pcre-regex \ --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client64/lib \ --enable-soap \ --with-gd \ --enable-zip \ --with-bz2 \ --with-zlib-dir \ --with-mysqli \ --with-libxml-dir=/usr/lib \ --with-jpeg-dir=/usr/lib \ --with-apxs2=/local/www/2.4.12/bin/apxs \ --with-pdo-oci \ --with-pdo-mysql \ --enable-mbstring \ --with-curl \ --with-libdir=lib64 \ --with-openssl
Exemple de retour sans erreur :
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php7.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/phpdbg/phpdbg.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
Traitement des erreurs
Lors du configure, des erreurs peuvent être détectées. Le script s'arrête alors avec un message.
Exemple de message d'erreur :
checking for the location of libXpm... no checking for FreeType 2... yes checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-webp-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes checking for png_write_image in -lpng... yes If configure fails try --with-xpm-dir=<DIR> configure: error: freetype-config not found.
L'erreur ci-dessus porte sur le sous-module freetype du module gd de PHP. En effet, lançant la commande suivante :
./configure --help
l'aide à la configuration de la compilation indique que l'option --with-freetype-dir
attend un répertoire comme valeur :
... --with-gd=DIR Include GD support. DIR is the GD library base install directory BUNDLED --with-webp-dir=DIR GD: Set the path to libwebp install prefix --with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix --with-png-dir=DIR GD: Set the path to libpng install prefix --with-zlib-dir=DIR GD: Set the path to libz install prefix --with-xpm-dir=DIR GD: Set the path to libXpm install prefix --with-freetype-dir=DIR GD: Set the path to FreeType 2 install prefix --enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support ...
Ce genre d'erreur est fréquente lors de la configuration de la compilation. Cela signifie qu'il manque des paquets nécessaire à la compilation. En l'occurrence, pour une une utilisation normale de freetype sur le serveur, seul le paquet freetype est nécessaire. Toutefois, en cas de compilation, il faut disposer des en-tête de développement en installant le paquet freetype-devel. :
yum install freetype-devel
La plupart de ces erreurs se traitent comme ceci : installer le paquet <module>-dev
ou <module>-devel
, où <module> correspond au module ayant généré une erreur.
Une fois l'installation réalisée, relancer la configuration de la compilation.
make
La configuration de la compilation étant précédemment réalisée, lancer simplement la compilation avec la commande suivante :
make
Exemple de retour de compilation réussie :
Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc pharcommand.inc directorytreeiterator.inc directorygraphiterator.inc invertedregexiterator.inc phar.inc Build complete. Don't forget to run 'make test'.
En cas d'erreur
Autant les erreurs de configuration de compilation sont facilement résolvables, autant les erreurs liées à l'étape de compilation sont particulières. Il faudra traiter au cas par cas et faire preuve d'un bon esprit d'analyse.
Par ailleurs, en cas d'erreur rencontrée lors de la compilation, il est recommandé de nettoyer le dossier des sources avant de relancer une configuration suivie d'une compilation avec la commande suivante :
make mostlyclean make clean make distclean make maintainer-clean
make install
Une fois la compilation terminée, les fichiers résultants se trouvent dans le dossier de compilation. Pour installer les fichiers dans les différents dossiers nécessaires à l'utilisation de PHP, lancer la commande suivante :
make install
Exemple de retour d'installation sans erreur :
Installing PHP SAPI module: apache2handler /local/www/2.4.12/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /local/www/2.4.12/modules /usr/lib64/apr-1/build/libtool --mode=install install libphp5.la /local/www/2.4.12/modules/ libtool: install: install .libs/libphp5.so /local/www/2.4.12/modules/libphp5.so libtool: install: install .libs/libphp5.lai /local/www/2.4.12/modules/libphp5.la libtool: install: warning: remember to run `libtool --finish /local/builds/php-5.6.40/libs' chmod 755 /local/www/2.4.12/modules/libphp5.so [activating module `php5' in /local/www/2.4.12/conf/httpd.conf] Installing shared extensions: /local/php/php5/lib64/extensions/no-debug-zts-20131226/ Installing PHP CLI binary: /local/php/php5/bin/ Installing PHP CLI man page: /local/php/php5/php/man/man1/ Installing PHP CGI binary: /local/php/php5/bin/ Installing PHP CGI man page: /local/php/php5/php/man/man1/ Installing build environment: /local/php/php5/lib64/build/ Installing header files: /local/php/php5/include/php/ Installing helper programs: /local/php/php5/bin/ program: phpize program: php-config Installing man pages: /local/php/php5/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /local/php/php5/lib64/php/ [PEAR] Archive_Tar - installed: 1.4.4 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.3 [PEAR] PEAR - installed: 1.10.7 Wrote PEAR system config file at: /local/php/php5/etc/pear.conf You may want to add: /local/php/php5/lib64/php to your php.ini include_path /local/builds/php-5.6.40/build/shtool install -c ext/phar/phar.phar /local/php/php5/bin ln -s -f phar.phar /local/php/php5/bin/phar Installing PDO headers: /local/php/php5/include/php/ext/pdo/
Il n'y a généralement pas d'erreur lors de cette étape.
Compilation PHP 7.4.7
Téléchargement de sources
Créer le dossier d'installation cible :
mkdir -p /local/php/php-7.4.7
Créer un lien symbolique pour pointer vers la version 7.4.7 :
ln -s php-7.4.7 /local/php/current
Créer le dossier de compilation, si inexistant :
mkdir -p /local/builds
Créer le dossier de téléchargement, si inexistant :
mkdir -p ~/downloads
Télécharger la version 5.6.40 avec la commande suivante :
wget -O ~/downloads/php-7.4.7.tar.gz https://www.php.net/distributions/php-7.4.7.tar.gz
La dézipper :
tar -xzf ~/downloads/php-7.4.7.tar.gz -C /local/builds/
Se rendre dans le dossier des sources et commencer la configuration de la compilation :
cd /local/builds/php-7.4.7
Prérequis
Au regard des options utilisées dans la section configure ci-dessous, les paquets suivants sont nécessaires :
yum install zlib-devel yum install bzip2-devel yum install libcurl-devel yum install libpng-devel yum install libicu-devel libicu yum install gcc-c++ libstdc++-devel yum install openldap-devel cyrus-sasl cyrus-sasl-devel yum install oniguruma-devel oniguruma yum install libxml2-devel xz-devel
configure
Lancer la configuration de la compilation avec les options désirées :
./configure \ --prefix=/local/php/php7 \ --with-ldap \ --enable-inline-optimization \ --enable-debug=no \ --enable-calendar \ --enable-ftp \ --enable-sysvsem \ --enable-sysvshm \ --disable-static \ --enable-mysqlnd \ --with-gettext \ --with-pcre-regex \ --with-oci8=instantclient,/usr/lib/oracle/10.2.0.4/client64/lib \ --enable-soap \ --with-gd \ --enable-zip \ --with-bz2 \ --with-zlib-dir \ --with-mysqli \ --with-libxml-dir=/usr/lib \ --with-jpeg-dir=/usr/lib \ --with-apxs2=/local/www/2.4.12/bin/apxs \ --with-pdo-oci \ --with-pdo-mysql \ --enable-mbstring \ --with-curl \ --with-libdir=lib64 \ --with-openssl
Exemple de retour sans erreur :
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php7.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/phpdbg/phpdbg.1 config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands
Traitement des erreurs
Lors du configure, des erreurs peuvent être détectées. Le script s'arrête alors avec un message.
Exemple de message d'erreur :
checking for the location of libXpm... no checking for FreeType 2... yes checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-webp-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes checking for png_write_image in -lpng... yes If configure fails try --with-xpm-dir=<DIR> configure: error: freetype-config not found.
L'erreur ci-dessus porte sur le sous-module freetype du module gd de PHP. En effet, lançant la commande suivante :
./configure --help
l'aide à la configuration de la compilation indique que l'option --with-freetype-dir
attend un répertoire comme valeur :
... --with-gd=DIR Include GD support. DIR is the GD library base install directory BUNDLED --with-webp-dir=DIR GD: Set the path to libwebp install prefix --with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix --with-png-dir=DIR GD: Set the path to libpng install prefix --with-zlib-dir=DIR GD: Set the path to libz install prefix --with-xpm-dir=DIR GD: Set the path to libXpm install prefix --with-freetype-dir=DIR GD: Set the path to FreeType 2 install prefix --enable-gd-jis-conv GD: Enable JIS-mapped Japanese font support ...
Ce genre d'erreur est fréquente lors de la configuration de la compilation. Cela signifie qu'il manque des paquets nécessaire à la compilation. En l'occurrence, pour une une utilisation normale de freetype sur le serveur, seul le paquet freetype est nécessaire. Toutefois, en cas de compilation, il faut disposer des en-tête de développement en installant le paquet freetype-devel. :
yum install freetype-devel
La plupart de ces erreurs se traitent comme ceci : installer le paquet <module>-dev
ou <module>-devel
, où <module> correspond au module ayant généré une erreur.
Une fois l'installation réalisée, relancer la configuration de la compilation.
make
La configuration de la compilation étant précédemment réalisée, lancer simplement la compilation avec la commande suivante :
make
Exemple de retour de compilation réussie :
Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc pharcommand.inc directorytreeiterator.inc directorygraphiterator.inc invertedregexiterator.inc phar.inc Build complete. Don't forget to run 'make test'.
En cas d'erreur
Autant les erreurs de configuration de compilation sont facilement résolvables, autant les erreurs liées à l'étape de compilation sont particulières. Il faudra traiter au cas par cas et faire preuve d'un bon esprit d'analyse.
Par ailleurs, en cas d'erreur rencontrée lors de la compilation, il est recommandé de nettoyer le dossier des sources avant de relancer une configuration suivie d'une compilation avec la commande suivante :
make mostlyclean make clean make distclean make maintainer-clean
make install
Une fois la compilation terminée, les fichiers résultants se trouvent dans le dossier de compilation. Pour installer les fichiers dans les différents dossiers nécessaires à l'utilisation de PHP, lancer la commande suivante :
make install
Exemple de retour d'installation sans erreur :
Installing PHP SAPI module: apache2handler /local/www/2.4.12/build/instdso.sh SH_LIBTOOL='/usr/lib64/apr-1/build/libtool' libphp5.la /local/www/2.4.12/modules /usr/lib64/apr-1/build/libtool --mode=install install libphp5.la /local/www/2.4.12/modules/ libtool: install: install .libs/libphp5.so /local/www/2.4.12/modules/libphp5.so libtool: install: install .libs/libphp5.lai /local/www/2.4.12/modules/libphp5.la libtool: install: warning: remember to run `libtool --finish /local/builds/php-5.6.40/libs' chmod 755 /local/www/2.4.12/modules/libphp5.so [activating module `php5' in /local/www/2.4.12/conf/httpd.conf] Installing shared extensions: /local/php/php5/lib64/extensions/no-debug-zts-20131226/ Installing PHP CLI binary: /local/php/php5/bin/ Installing PHP CLI man page: /local/php/php5/php/man/man1/ Installing PHP CGI binary: /local/php/php5/bin/ Installing PHP CGI man page: /local/php/php5/php/man/man1/ Installing build environment: /local/php/php5/lib64/build/ Installing header files: /local/php/php5/include/php/ Installing helper programs: /local/php/php5/bin/ program: phpize program: php-config Installing man pages: /local/php/php5/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /local/php/php5/lib64/php/ [PEAR] Archive_Tar - installed: 1.4.4 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.4.3 [PEAR] PEAR - installed: 1.10.7 Wrote PEAR system config file at: /local/php/php5/etc/pear.conf You may want to add: /local/php/php5/lib64/php to your php.ini include_path /local/builds/php-5.6.40/build/shtool install -c ext/phar/phar.phar /local/php/php5/bin ln -s -f phar.phar /local/php/php5/bin/phar Installing PDO headers: /local/php/php5/include/php/ext/pdo/
Il n'y a généralement pas d'erreur lors de cette étape.
Intégration des binaires PHP dans le PATH
Version unique de PHP
Dans le cas d'une version unique de PHP installée sur le serveur, il est possible d'intégrer l'ensemble des binaires PHP disponibles dans le PATH en ajoutant la ligne suivantes dans un des fichiers profile
du serveur :
export PATH=$PATH:/local/php/5.6.40/bin
Le chemin /local/php/5.6.6/bin
est un exemple, l'adapter au besoin.
La modification du PATH se fera automatiquement à chaque ouverture de session. Pour une prise en compte immédiate, il faut sourcer le fichier. Par exemple, si la modification du PATH a été indiquée dans le fichier /etc/profile.d/php.sh
, le sourcer en faisant :
. /etc/profile.d/php.sh
De cette façon, les commandes suivantes seront toutes disponibles depuis n'importe quel endroit du serveur, avec n'importe quel utilisateur :
- pear
- peardev
- pecl
- phar
- phar.phar
- php
- php-cgi
- php-config
- phpize
Pour n'inclure que certains des binaires ci-dessus, se reporter à la section Versions multiples de PHP.
Versions multiples de PHP
Dans le cas de plusieurs versions de PHP installées sur le serveur, les binaires portant exactement le même nom, il faudra les différencier selon la version désirée.
Ainsi, pour chaque binaire désiré dans le PATH, il faudra créer un lien symbolique depuis un PATH existant du serveur vers le binaire en question.
Versions majeures
S'il n'y a que deux versions majeures différentes sur le serveur, la création des liens symboliques suivants dans le PATH /usr/bin
avec le numéro de version majeure est suffisant :
ln -s /local/php/php5/bin/php /usr/bin/php5 ln -s /local/php/php7/bin/php /usr/bin/php7
De cette façon, le binaire php sera accessible depuis n'importe tout sur le serveur, avec n'importe quel utilisateur, depuis la commande php5 pour du PHP 5 et depuis la commande php7 pour du PHP 7.
Versions mineures
En cas de présence différentes version mineures de PHP, en s'inspirant de la section Versions majeures, il faudra simplement rajouter un chiffre distinguant sur le numéro de version.
Par exemple, en cas de présence des versions 5.6.40, 5.6.6, 7.2.19 et 7.3.6, il faudra créer les liens symboliques suivants :
ln -s /local/php/5.6.40/bin/php /usr/bin/php5640 ln -s /local/php/5.6.6/bin/php /usr/bin/php566 ln -s /local/php/7.2.19/bin/php /usr/bin/php72 ln -s /local/php/7.3.6/bin/php /usr/bin/php73
Fichier php.ini
Nouvelle installation
En cas de nouvelle installation, pour partir d'une configuration par défaut, il est possible de s'appuyer sur un des deux fichiers modèles fournis par PHP.
Ces fichiers se trouvent dans le dossier de build de PHP. Exemple pour la version 5.6.40 en lançant la commande suivante :
ls -1 /local/builds/php-5.6.40/php.ini*
Exemple de retour :
/local/builds/php-5.6.40/php.ini-development /local/builds/php-5.6.40/php.ini-production
Pour retrouver ces informations, il est possible de consulter le fichier INSTALL
dans le dossier de build.
Exemple d'informations relatives au fichier php.ini pour PHP 5.6.40 :
210 13. Setup your php.ini file:
211
212 cp php.ini-development /usr/local/lib/php.ini
213
214 You may edit your .ini file to set PHP options. If you prefer your
215 php.ini in another location, use --with-config-file-path=/some/path in
216 step 10.
217
218 If you instead choose php.ini-production, be certain to read the list
219 of changes within, as they affect how PHP behaves.
Exemple d'informations relatives au fichier php.ini pour PHP 7.2.19 :
237 6. Setup your php.ini
238 cp php.ini-development /usr/local/lib/php.ini
239
240 You may edit your .ini file to set PHP options. If you prefer
241 having php.ini in another location, use
242 --with-config-file-path=/some/path in step 5.
243 If you instead choose php.ini-production, be certain to read the
244 list of changes within, as they affect how PHP behaves.
NB : Les chemins indiqués sont, bien évidemment, à adapter selon l'arborescence dans laquelle PHP a été installé.
Par exemple, en PHP 5.6.40, pour s'appuyer sur le php.ini de développement, lancer la commande suivante :
cp /local/builds/php-5.6.40/php.ini-development /local/php/php5/lib64/php.ini
Autre exmple, en PHP 7.2.19, pour s'appuyer sur le php.ini de production, lancer la commande suivante :
cp /local/builds/php-7.2.19/php.ini-production /local/php/php7/lib64/php.ini
Il faut ensuite éditer le fichier php.ini
pour l'adapter aux besoins.
Installation existante
Pour identifier le fichier php.ini
chargé par PHP, lancer la commande suivante :
php --ini
Exemple de retour :
Configuration File (php.ini) Path: /local/php/php5/lib64 Loaded Configuration File: /local/php/php5/lib64/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none)