大网数据广告活动
服务器运维问答

Apache doesn't want to load GnuPG PHP

· 52CE 我爱测

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 whi…

问题原文

原帖链接 · S.I. · CC BY-SA 3.0

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

已采纳解答

原帖链接 · Safado · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。