1

I've asked this in SO but maybe here is more suitable to ask. I'm installed GnuPG via Pecl. Generate pub/priv keys etc.. I have in php.ini

extension=gnupg.so

When I try to run simple code I've got undefined gnupg_init() error which by my understands is meaning that module isn't loaded.

Fatal error: Uncaught Error: Call to undefined function gnupg_init() 

This is the code which I trying to run

putenv('GNUPGHOME=/home/stan/.gnupg');
$res = gnupg_init();
gnupg_seterrormode($res,GNUPG_ERROR_WARNING);
gnupg_addencryptkey($res,"myfingerprint");
$enc = gnupg_encrypt($res, "just a test");
echo $enc;

The system is ubuntu + apache. Here are permissions of the .gnupg/

srwxrwxr-x 1 stan stan    0 Aug 16 08:12 S.gpg-agent
-rw------- 1 stan stan   32 Aug 16 10:02 pubring.kbx~
drwx------ 2 stan stan 4096 Aug 16 10:04 private-keys-v1.d
-rw-rw-r-- 1 stan stan 1361 Aug 16 10:04 pubring.kbx
drwx------ 2 stan stan 4096 Aug 16 10:04 openpgp-revocs.d
-rw------- 1 stan stan 2603 Aug 16 10:19 secring.gpg
-rw------- 1 stan stan 1209 Aug 16 10:19 pubring.gpg~
-rw------- 1 stan stan 1360 Aug 16 10:19 trustdb.gpg
-rw------- 1 stan stan  600 Aug 16 10:19 random_seed
-rw------- 1 stan stan 1209 Aug 16 10:19 pubring.gpg

Here is my /var/www/

drwxrwsr-x 3 stan www-data 4096 Jul 14 11:23 www
drwxr-sr-x 7 stan www-data 4096 Aug 16 09:59 html

I have also confirmation that is installed and loaded

$ php --info | grep gnupg
gnupg
gnupg support => enabled
S.I.
  • 198
  • 3
  • 14
  • Wnat OS are you on? php --info is not going to give you the same `php` that Apache is using (mod-php). Create a php file with `` and then view that page from your browser. Look through that info page and tell us whether you see gnupg is enabled. – Safado Aug 16 '16 at 14:42
  • OS is Ubuntu 16* and I've checking which `` and simply I didn't see gnupg in there.. – S.I. Aug 16 '16 at 14:43
  • I've changed `chgrp` and `chown` `.gnupg/` to `www-data` instead of `stan` but still same.. And will be same because it's seems that the issue is with module loading into php since everything else is fine or at least look like fine.. – S.I. Aug 16 '16 at 14:53

1 Answers1

1

It might depend on what repository you use and packages are available. As noted in my comment, when you run phpinfo(); inside a php script and load it from your browser, you'll see that mod_php isn't loading the gnupg extension.

On my CentOS servers, we use the Remi repos for PHP. He has a package called php-pecl-gnupg. When I install it, it installs the necessary shared objects for mod_php and I can confirm it's available to my web code.

So we've seen that command line php and mod_php in apache don't load the same configurations, so doing php --info doesn't necessarily show you what mod_php in Apache is configured with. Look in your phpinfo() file and see what configuration file it's reading from (it shows in the first few lines). Then make sure you have extension=gnupg.so in that config file and make sure that it's looking in the same directory for the extension.

Safado
  • 4,786
  • 7
  • 37
  • 54
  • I checked with `phpinfo()` and I don't see it. Can you explain me this: `Then make sure you have extension=gnupg.so in that config file and make sure that it's looking in the same directory for the extension.` Isn't enough just add `extension=gnupg.so` to the `php.ini` or I must add it somewhere else? – S.I. Aug 17 '16 at 05:52
  • Okay, I've completely remove `php7` from my system then completely removed `pecl gnupg`. After this I've installed `php 5.6` and `gnupg-1.3.6`(was 1.4 with php7) then I've added `extension=gnupg.so` to my php.ini + restart apache and now I see the extension in `phpinfo();` – S.I. Aug 17 '16 at 09:09
  • So I think the problem is in php7 + gnupg-1.4 – S.I. Aug 17 '16 at 09:10
  • I'm glad you got it resolved. What I meant by the above comment was it looks like you had two different php.ini files, So adding "extension=gnupg.so" wouldn't be enough.. you'd need to make sure that the directory that was configured for `extension_dir` actually contained the gnupg.so file. I was just suggesting that you double check is all. – Safado Aug 17 '16 at 21:26