Question

I've upgraded my MacBook to Mavericks and ruined my development environment. The problem I have right now is that my pear/pecl still tries to install for my previous (5.3) version of PHP instead of version 5.4.

PHP version:

$ php -v
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

Pear

$ pear version
PEAR Version: 1.9.4
PHP Version: 5.4.17
Zend Engine Version: 2.4.0
Running on: Darwin MBP-retina.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64

If I install apc with

$ sudo pecl install apc
downloading APC-3.1.13.tgz ...
Starting to download APC-3.1.13.tgz (171,591 bytes)
.....................................done: 171,591 bytes
55 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
...
Build process completed successfully
Installing '/usr/local/Cellar/php53/5.3.26/include/php/ext/apc/apc_serializer.h'
Installing '/usr/local/Cellar/php53/5.3.26/lib/php/extensions/no-debug-non-zts-20090626/apc.so'
install ok: channel://pecl.php.net/APC-3.1.13
Extension apc enabled in php.ini

And enable the apc module in my php.ini php -v changes to this:

$ php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20100525/apc.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20100525/apc.so, 9): image not found in Unknown on line 0
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

So pecl installs my apc extension in /usr/local/Cellar/php53/5.3.26/lib/php/extensions/no-debug-non-zts-20090626 and php expects it in /usr/lib/php/extensions/no-debug-non-zts-20100525/.

Simply making a symlink gives the following error:

$ php -v
PHP Warning:  PHP Startup: apc: Unable to initialize module
Module compiled with module API=20090626
PHP    compiled with module API=20100525
These options need to match
 in Unknown on line 0
PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

So that's not a solution.

Can anybody point me in the right direction? I really don't have a clue what is going on here.

Was it helpful?

Solution 2

The solution was pretty simple. I had to make modifications to my pecl config. It turned out that these two command did the trick:

sudo pear config-set php_ini /etc/php.ini
sudo pecl config-set bin_dir /usr/bin/

pecl used the wrong phpize. There were two versions of the phpize. The same counts for my php.ini file.

OTHER TIPS

In my case, I was attempting to install Gearman.

pecl install gearman would install it incorrectly.

php -i would show:

PHP Extension => 20100525

Yet pecl would install using:

PHP Api Version:         20090626

After changing my config settings to use:

First Fix

sudo pecl config-set php_ini /etc/php.ini
sudo pecl config-set php_bin /usr/bin/php5

I noticed that I would still get

WARNING: php_bin /usr/bin/php5 appears to have a suffix 5, but config variable php_suffix does not match

You can resolve this by using the config setting:

Additional Fix

sudo pear config-set php_suffix 5

Why was this a problem?

For me, I got into this problem because I added a custom PPA and reinstalled PHP. This meant that my previous install of php5-dev was out of sync.

You if you ever get into the same situation, you might just want to run..

apt-get remove php5-dev
pecl uninstall <extensionname>
apt-get install php5-dev
apt-get remove php5-pear
apt-get install php5-pear
pecl install <extensionname>

Alternatively, you can download the source and run phpize.

None of the other answers (as yet) seem to address having multiple "co-installable" PHP versions while wanting to build a given extension for all installed PHP versions.

To illustrate the scenario in which I find myself (I'm using the Ondrej Surý PHP PPAs for Ubuntu 16.04 LTS):

root@localhost:~# ls -lah /usr/bin/*php*
-rwxr-xr-x  1 root   root     11K Apr 19 12:50 dh_php
-rwxr-xr-x  1 root   root    3.1K Apr  5  2016 dh_phpcomposer
-rwxr-xr-x  1 root   root    5.4K Apr  5  2016 dh_phppear
lrwxrwxrwx  1 root   root      21 Jul 24 00:44 php -> /etc/alternatives/php
-rwxr-xr-x  1 root   root    4.3M Jul  6 10:04 php5.6
-rwxr-xr-x  1 root   root    4.3M Jul  6 10:04 php7.0
-rwxr-xr-x  1 root   root    4.4M Aug  4 14:22 php7.1
lrwxrwxrwx  1 root   root      28 Jul 24 00:44 php-config -> /etc/alternatives/php-config
-rwxr-xr-x  1 root   root    4.3K Jul  6 10:03 php-config5.6
-rwxr-xr-x  1 root   root    4.1K Jul  6 10:03 php-config7.0
-rwxr-xr-x  1 root   root    4.1K Aug  4 14:21 php-config7.1
lrwxrwxrwx  1 root   root      24 Jul 24 00:44 phpize -> /etc/alternatives/phpize
-rwxr-xr-x  1 root   root    4.7K Jul  6 10:03 phpize5.6
-rwxr-xr-x  1 root   root    4.6K Jul  6 10:03 phpize7.0
-rwxr-xr-x  1 root   root    4.6K Aug  4 14:21 phpize7.1

pecl install extension-name does the job for PHP 7.1, but not the others.

The other anwsers indicate that while it's possible to uninstall/reinstall php*-dev, I'd much rather not, given the intentional, co-installed PHP versions on the system.

One solution is to build the extension for each version present on the system.

This snippet demonstrates building with PHP 5.6, but I've done the same for 7.0 and 7.1 and the steps are the same.

This example demonstrates cloning the extension from a Git repository, but one may use any source directory.

(# indicates that you must be root or use sudo)

# apt-get install php-dev

# cd ~

# git clone https://github.com/vendor/extension-name

# cd ./extension-name

# phpize5.6

# ./configure --with-php-config=/usr/bin/php-config5.6

# make clean

# make

# make install

# ln -s /etc/php/5.6/mods-available/extension-name.ini /etc/php/5.6/fpm/conf.d/20-extension-name.ini

# service php5.6-fpm reload

There is a way to switch PHP version on Ubuntu:

sudo update-alternatives --set php /usr/bin/php5.6

and optionally:

sudo update-alternatives --set phar /usr/bin/phar5.6
sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6
sudo update-alternatives --set phpize /usr/bin/phpize5.6
sudo update-alternatives --set php-config /usr/bin/php-config5.6

Source: https://superuser.com/a/1100911/371795

Better to reinstall phpize extensions as it will be used by PECL and not make hacks.

Do next (php 5.5 => php 5.6 example) :

sudo apt-get remove php5-dev
sudo apt-get install php5.6-dev 

(you can change 5.6 to version you need)

Then:

sudo pecl install extensionname

Encountered similar problem recently.

(Debian, PHP 7.3 just installed, was using PHP 7.2)

If anybody tried the highest voted answer but still not working. Here are the steps to debug:

  • Remove all other php versions, especially the dev package (php7.2-dev in my case)
  • install the dev package for the current version (php7.3-dev)

And basically that's it.

Reason:

PECL requires phpize which is part of php-dev package. If phpize for the current version is not found, if will look for the previous version, which resulting a older PHP API number

On Ubuntu 16.04, when using ppa:ondrej/php (and probably other alternatives), in order to install pecl/php extensions for php 5.6, you have to do the following:

pecl config-set ext_dir /usr/lib/php/20131226
pecl config-set php_bin /usr/bin/php5.6
pecl config-set php_ini /etc/php/5.6/cli/php.ini
pear config-set ext_dir /usr/lib/php/20131226
pear config-set php_bin /usr/bin/php5.6
pear config-set php_ini /etc/php/5.6/cli/php.ini
update-alternatives --config php #select php 5.6
update-alternatives --config php-config #select php 5.6
update-alternatives --config phpize #select php 5.6

Next you can use pecl as usual:

pecl install raphf-1.1.2

downloading raphf-1.1.2.tgz ... Starting to download raphf-1.1.2.tgz (15,915 bytes) ......done: 15,915 bytes 8 source files, building

running: phpize

Configuring for:

PHP Api Version: 20131106

Zend Module Api No: 20131226

Zend Extension Api No: 220131226

...

install ok: channel://pecl.php.net/raphf-1.1.2

Extension raphf enabled in php.ini

I noticed that, when no extension are enabled in php.ini, pecl add the line extension="xxx.so" at the beginning of the php.ini, so I usually move it at the end of the file, manually, and after it's ok for the next extensions.

Depending of what you have on your system, it may be necessary to rollback your changes after install, especially for the default php version to use, with update-alternatives

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top