Problems when compiling PHP Extensions with Pecl

0
(0)

This is just a very short post to offer some advice to any developers who are adding PHP extensions to their wordpress environment using the pecl tool. This is a tool which compiles extensions and links them to the PHP binary so they run correctly. When the install process takes place, a few tools are used to create the build files etc and run the compile process.

If you have more than one version of php installed it’s easy to get into the situation where you run the command

pecl install module

and after the process completes you find that the module won’t load. Normally there will be a message about the extension you have just added being missing. This has happened to me on a couple of occasions on an Ubuntu machine and the last time it took me about 30 minutes digging around before I found the problem, so I thought I’d add this post and hopefully save someone else some time.

In a nutshell, the problem I had was that the extension was being compiled for the wrong version of PHP. That part was actually quite easy to find out; running

php --version

showed me that the version I was using was PHP 7.1 so I assumed one of the other versions I had installed (7.0 and 7.2) had been used to compile the extension. I guessed that the problem was the phpize program and sure enough running

sudo update-alternatives --list phpize

showed me that the version which was being used was for php 7.2.

With that corrected I expected everything to work and re-ran the pecl install command, only to find the same problem. It was only after 30 minutes messing about and searching google that I found there is also a php-config program which also needs to be the correct version. After I’d also run

sudo update-alternatives --set php-config /usr/bin/php-config7.1

I found the pecl install program installed the extension into the correct path and everything worked properly.

So the thing to remember is that there are actually 3 different commands to run to change both the PHP version and the build system.

sudo update-alternatives --set php /usr/bin/php7.1
sudo update-alternatives --set phpize /usr/bin/phpize7.1
sudo update-alternatives --set php-config /usr/bin/phpconfig7.1

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Please consider sharing on social media!

Leave a Reply

Your email address will not be published. Required fields are marked *

Young girl in Sunlight Previous post Favourite pictures – my Daughter Emma
The River Avon at Stratford on Avon Next post The River Avon at Stratford-on-Avon