Debugging GNUPG

I have this error on my server:
PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/gnupg.so'

And this is how I fixed it:

Short answer

Remove old php dev and install a new one that fits your php version:

sudo pecl uninstall gnupg
sudo apt-get remove php5.6-dev
sudo apt-get install php7.1-dev
sudo pecl install gnupg

TL;DR

Extension dir for php 5.6 is `/usr/lib/php/20131226` and extension dir for php 7.0 is `/usr/lib/php/20151012` as this command shows:

php -r "print phpinfo();" | grep "extension_dir"

Pecl installs gnupg in `/usr/lib/php/20131226/gnupg.so` because the pecl was installed when php 5.6 is enabled

pecl list-files gnupg

**Conclusion:**

PHP 7.0 uses a different extension directory than where the gnupg is installed.

**First try which didn’t work**:

Create symlink for gnup.so inside the php 7.0 extension directory that points to gnup.so inside php 5.6

sudo ln -s /usr/lib/php/20131226/gnupg.so /usr/lib/php/20151012/gnupg.so

**Results in**:

Warning: PHP Startup: gnupg: Unable to initialize module
Module compiled with module API=20131226
PHP compiled with module API=20151012

**Second try which also didn’t work**:

1. Uninstall pecl extension: `sudo pecl uninstall gnupg`
2. Activate php v 7.0
3. Install gnupg again: `sudo pecl install gnupg`

Gives same compiling error.

**Other try and error**:

Install a compiled version of the gnupg that works with php 7.0: see php [docs here][1]

Download latest pecl extension source from https://github.com/php-gnupg/php-gnupg

Find which configuration file is used by your PHP 7.0 installation

php --ini
Configuration File (php.ini) Path: /etc/php/7.0/cli

Compile the pecl extension:
cd {downloaded extension folder}
phpize
./configure –with-php-config=/home/vagrant/Downloads/php-src-PHP-7.0/scripts/php-config

**Check if gnupg is installed**

php -r ‘var_dump(function_exists(“gnupg_decrypt”));’;
[1]: http://php.net/manual/en/install.pecl.phpize.php

Compile php dev source
Download: https://github.com/php/php-src/tree/PHP-7.0
Create configuration build: ./buildconf
Init a config: ./configure –prefix=/usr/local/php7/7.0.0 –localstatedir=/usr/local/var –sysconfdir=/usr/local/etc/php/7 –with-config-file-path=/usr/local/etc/php/7 –with-config-file-scan-dir=/usr/local/etc/php/7/conf.d –mandir=/usr/local/php7/7.0.0/share/man

You can then check out the branch you want to build, for example:

PHP 5.4: git checkout PHP-5.4
PHP 5.5: git checkout PHP-5.5
PHP 5.6: git checkout PHP-5.6
PHP 7.0: git checkout PHP-7.0
PHP HEAD: git checkout master

Leave a Comment

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