当系统中安装了多个php版本时,如何使用pecl为特定的php版本安装php扩展?
根据本手册,我已经在Ubuntu上从PPA安装了php5.6和php7.0
I have installed both php5.6 and php7.0 from PPA on Ubuntu according to this manual
http://lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu
但是我没有得到如何使用pecl
为php5.6或php7.0安装扩展的信息.
But I didn't get how to install extensions using pecl
for php5.6 or php7.0.
例如,我已经在php5.6中安装了libevent
或amqp
版本.
For example I have already installed version of libevent
or amqp
in php5.6.
现在,当我键入pecl install libevent
且我的活动php版本是php7.0时(使用已安装的update-alternatives --set php /usr/bin/php7.0),
pecl returns message that
libevent`.
Now when I type pecl install libevent
and my active php version is php7.0 (using update-alternatives --set php /usr/bin/php7.0),
peclreturns message that
libevent` already installed.
但是它只为php5.6安装(当此版本处于活动状态时),现在我想为php7.0安装它.
But it was installed only for php5.6 (when this version was active) and now I want to do it for php7.0.
哪些命令可以帮助我?
UPD
我发现以下命令可将pecl切换到php7.0并将其打包到可执行的bash脚本中:
I have found this commands for switch pecl to php7.0 and packet them to executable bash scripts:
#!/bin/bash
sudo update-alternatives --set php /usr/bin/php7.0
sudo pecl config-set php_ini /etc/php/7.0/cli/php.ini
sudo pecl config-set ext_dir /usr/lib/php/20151012/
sudo pecl config-set bin_dir /usr/bin/
sudo pecl config-set php_bin /usr/bin/php7.0
sudo pecl config-set php_suffix 7.0
和适用于php5.6
and for php5.6
#!/bin/bash
sudo update-alternatives --set php /usr/bin/php5.6
sudo pecl config-set php_ini /etc/php/5.6/cli/php.ini
sudo pecl config-set ext_dir /usr/lib/php/20131226/
sudo pecl config-set bin_dir /usr/bin/
sudo pecl config-set php_bin /usr/bin/php5.6
sudo pecl config-set php_suffix 5.6
但是它们无济于事,即使我切换到php7,pecl仍会给我list
已安装的php5.6扩展名.
But they are not help, pecl still gives me list
of already installed extensions to php5.6, even if I switched to php7.
pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
amqp 1.7.1 stable
libevent 0.1.0 beta
stats 1.0.3 stable
对于php7.0应该为空!
It should be empty for php7.0 !
如何解决问题?
UPD
对于amqp,我刚刚安装了php-amqp软件包,而没有使用pecl.
For amqp I have just installed php-amqp package without using pecl.
apt-get install php-amqp
并且php7的libevent仍然不存在. 但是我还没有找到在5.6和7版本之间切换pecl安装的方法,因此问题仍然悬而未决.
And libevent still not exists for php7. But I hadn't found a way to switch pecl installation between 5.6 and 7 version, so question is still open.
在尝试编写此脚本时,这是最适合我的方法(以防其他人像我那样遇到此问题):
Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):
$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>
$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>
$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>
-d php_suffix=<version>
件允许您在运行时设置配置值,而不是用pecl config-set
预先设置它们. uninstall -r
位实际上并没有从文档中卸载它:
The -d php_suffix=<version>
piece allows you to set config values at run time vs pre-setting them with pecl config-set
. The uninstall -r
bit does not actually uninstall it (from the docs):
vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages. More than one package may be
specified at once. Prefix with channel name to uninstall from a
channel not in your default channel (pecl.php.net)
Options:
...
-r, --register-only
do not remove files, only register the packages as not installed
...
卸载行是必需的,否则即使安装了其他PHP版本,也要安装它会删除任何以前安装的版本(例如:如果软件包仍注册为已安装,则安装PHP 7.0的扩展名将删除5.6版本)
The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).