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:
- Uninstall pecl extension:
sudo pecl uninstall gnupg
- Activate php v 7.0
- Install gnupg again:
sudo pecl install gnupg
Gives same compiling error.
Final solution:
Install a compiled version of the gnupg that works with php 7.0: see php docs here
Check if gnupg is installed
php -r 'var_dump(function_exists("gnupg_decrypt"));';