1

I have 2 versions of php installed on my ubuntu php5.6 and php7. 5.6 is set as active version. Now I am trying to install GPG using below line of code, and it installs it under /etc/php/7.0 directory.

sudo apt-get install php-gnupg

How to install it for php5.6?

bignose
  • 30,281
  • 14
  • 77
  • 110
Asit
  • 458
  • 4
  • 14
  • 1
    Question is: how did you manage to install both php versions in parallel? That can obviously not have happened by using the provided packages. So I suggest you follow the same approach you did at that time to install this extension now. – arkascha Oct 26 '16 at 10:25
  • Ubuntu 16.04 comes with php7. I installed 5.6 later. Obviously we can select any version of php to use. – Asit Oct 26 '16 at 11:06
  • You indeed can switch between versions using the normal package management. But you cannot install different versions in parallel. That is because the packages are in conflict. So the question remains: how did you install that second version of php? – arkascha Oct 26 '16 at 11:13
  • you can enable/disable mod in apache that will point to specific version of php while running your application. http://askubuntu.com/questions/761713/how-can-i-downgrade-from-php-7-to-php-5-6-on-ubuntu-16-04 – Asit Oct 26 '16 at 12:32
  • That undoubtedly is true. But it does not at all answer _how_ you installed that second version in parallel. I insist on that because this will tell you how you can add that extension. – arkascha Oct 26 '16 at 12:39
  • @arkascha You can install both with `apt-get libapache2-mod-php5.6` and `apt-get libapache2-mod-php7.0` I have an Ansible role that installs them both.. – numediaweb Feb 10 '17 at 11:10
  • here's my answer to the more generic question on how to install gnupg for php in ubuntu https://stackoverflow.com/questions/48958165/php-gnupg-is-not-showing-up-as-an-extension-in-phpinfo-and-i-cant-use-it-in-p – Bahman.A Jan 20 '20 at 19:43

1 Answers1

2

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.

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"));';
numediaweb
  • 16,362
  • 12
  • 74
  • 110