PHP 7.3¶
Changer de version de PHP:¶
$ brew unlink php@7.3 && brew link --force --overwrite php@5.6
On installe un petit utilitaire PHP Switcher Script
$ curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /usr/local/bin/sphp
$ chmod +x /usr/local/bin/sphp
https://gist.github.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw/b51e5f561dc6492249ac167813b9b40dcdd72bd0/sphp.sh
Ensuite pour changer de version:
$ sphp 7.3
Par exemple, pour passer de 7.2.13. à 7.3.0_1:
$ sphp 7.3
Switching to php@7.3
Switching your shell
Unlinking /usr/local/Cellar/php@7.2/7.2.13... 25 symlinks removed
Unlinking /usr/local/Cellar/php/7.3.0_1... 0 symlinks removed
Linking /usr/local/Cellar/php/7.3.0_1... 24 symlinks created
You will need sudo power from now on
Switching your apache conf
Password:
Restarting apache
PHP 7.3.0 (cli) (built: Jan 3 2019 10:08:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.0, Copyright (c) 1999-2018, by Zend Technologies
All done!
Il y a un autre utilitaire (brew-php-switcher):
$ brew info brew-php-switcher
brew-php-switcher: stable 2.0, HEAD
Switch Apache / Valet / CLI configs between PHP versions
https://github.com/philcook/php-switcher
Not installed
Extensions:¶
Liste des extensions (Homebrew):¶
$ brew search php73
Installer des extensions (avec PECL):¶
Requiert autoconf: brew install autoconf
$ pecl uninstall -r xdebug
$ pecl install xdebug
$ pecl install yaml
$ pecl install redis
$ pecl install apcu
$ pecl install memcached
$ pecl install imagick
# Pour une version spécifique:
$ pecl install xdebug-2.7.0beta1
Pour les activer, créez un fichier de configuration dans /usr/local/etc/php/7.3/conf.d/
bruno@silverbook:/usr/local/etc/php/7.3/conf.d$ l
total 32
drwxr-xr-x 6 bruno admin 192 4 jan 19:32 .
drwxr-xr-x 9 bruno admin 288 3 jan 19:34 ..
-rw-r--r-- 1 bruno admin 72 4 jan 16:09 ext-opcache.ini
-rw-r--r-- 1 bruno admin 172 4 jan 18:58 ext-xdebug.ini
-rw-r--r-- 1 bruno admin 81 4 jan 18:43 ext-yaml.ini
-rw-r--r-- 1 bruno admin 87 13 déc 07:12 fix-jit.ini
bruno@silverbook:/usr/local/etc/php/7.3/conf.d$ nano ext-xdebug.ini
[xdebug]
zend_extension="/usr/local/lib/php/pecl/20180731/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
Chaque version de PHP a son propre répertoire d'extensions:
/usr/local/lib/php/pecl/20160303 ← 7.1
/usr/local/lib/php/pecl/20170718 ← 7.2
/usr/local/lib/php/pecl/20180731 ← 7.3
/usr/local/lib/php/pecl/20190902 ← 7.4
/usr/local/lib/php/pecl/20200930 ← 8.0
/usr/local/Cellar/php@7.4/7.4.14_1/pecl/20190902/
Installer une extension (depuis les sources):¶
# Installation de ssh2:
$ brew install libssh2
$ cd ~/Downloads
$ git clone https://git.php.net/repository/pecl/networking/ssh2.git
$ cd ssh2
$ phpize
$ ./configure
$ make
$ make install
$ cd /usr/local/etc/php/7.3/conf.d
$ nano ext-ssh2.ini
Ajouter au fichier:
extension="ssh2.so"
# Installation de Xdebug:
$ wget http://xdebug.org/files/xdebug-x.x.x.tgz
$ tar -xzvf xdebug-x.x.x.tgz
$ cd xdebug-x.x.x
$ phpize
$ ./configure
$ make
$ make install
# Installation de imagick:
git clone https://github.com/Imagick/imagick
cd imagick
phpize && ./configure
make
make install
Activer / désactiver Xdebug:
❯ curl -L https://gist.githubusercontent.com/rhukster/073a2c1270ccb2c6868e7aced92001cf/raw/c1629293bcf628cd6ded20c201c4ef0a2fa79144/xdebug > /usr/local/bin/xdebug
❯ chmod +x /usr/local/bin/xdebug
# Utilisation:
❯ xdebug on
❯ xdebug off
https://pecl.php.net
https://github.com/Imagick/imagick.git
https://github.com/php/pecl-file_formats-yaml.git
Erreurs:¶
Warning: preg_replace(): JIT compilation failed: no more memory in¶
Il s'agit d'un bug connu de PHP 7.3.
2 solutions:
- désinstaller php 7.3
$ brew uninstall php@7.3
- désactiver la compilation PCRE JIT dans le php.ini
pcre.jit=0
Pour désactiver la compilation PCRE JIT, on peut aussi créer un fichier fix-jit.ini
dans /usr/local/etc/php/7.3/conf.d
et y ajouter:
; My php.ini settings
; Fix for PCRE "JIT compilation failed" error
[Pcre]
pcre.jit=0
Dernière mise à jour:
November 9, 2023