Pecl with multiple PHP versions


(Karl Shea) #1

Is there a recommendation for how to use pecl with multiple PHP versions installed? Occasionally I need to switch between PHP 7 and PHP 5.6 for older projects, and with the new changes pecl only builds against one version.

It almost seems like the pecl directory shouldn’t be /usr/local/lib/php/pecl but instead /usr/local/lib/php/7.0/pecl and /usr/local/lib/php/5.6/pecl?


(Eduard Rozenberg) #2

If you’re using the recent homebrew php versions, they store extensions in a directory that looks like /usr/local/lib/php/pecl/20170718

I believe the datestamp indicates the PHP API version for the modules in that directory.

To install a module for php5, you’d do something like
/usr/local/Cellar/php/5.x.x/bin/pecl install some_module_name

To install a module for php7, you’d do something like
/usr/local/Cellar/php/7.x.x/bin/pecl install some_module_name

The last thing is you’d have to consider maintainining two separate php.ini files.

The PHP 7 ini file would contain something like:

extension_dir = "/usr/local/lib/php/pecl/20170718`
zend_extension="mymodule.so"

The PHP 5 ini file would contain something like:

extension_dir = "/usr/local/lib/php/pecl/<whatever date stamp php5 modules are in>
zend_extension="mymodule.so"

(Karl Shea) #3

Something strange is going on then:

cat /usr/local/etc/php/5.6/php.ini | grep extension_dir
extension_dir = "/usr/local/lib/php/pecl/20131226"



/usr/local/Cellar/php@5.6/5.6.35/bin/pecl list-files xdebug
Installed Files For xdebug
==========================
Type Install Path
doc  /usr/local/share/pear/doc/xdebug/contrib/tracefile-analyser.php
doc  /usr/local/share/pear/doc/xdebug/contrib/xt.vim
doc  /usr/local/share/pear/doc/xdebug/CREDITS
doc  /usr/local/share/pear/doc/xdebug/LICENSE
doc  /usr/local/share/pear/doc/xdebug/xdebug.ini
doc  /usr/local/share/pear/doc/xdebug/README.rst
src  /usr/local/Cellar/php@7.0/7.0.29/pecl/20151012/xdebug.so

(Andy Miller) #4

BTW, I’ve updated my guide to cover handling the new Homebrew/core + PECL package installation for multiple PHP versions: https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions


(许磊) #5

安装多个PHP版本是没问题的,你有试过给每一个php版本单独安装扩展的情况吗?


(Karl Shea) #6

Thanks, that helped. I think the issue was that I wasn’t closing/reopening my terminal windows after unlink/link and pecl was getting confused.