本文介绍了PHP Gnupg未在phpinfo()中显示为扩展名,我无法在php中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自制软件安装了gnupg和gpgme.我还链接了这两个文件,并通过运行brew gnupg install和brew gpgme install来确保它们已安装并链接,并得到确认安装和版本的消息.

I have gnupg and gpgme installed using homebrew.I also linked both and made sure they are installed and linked by running brew gnupg install and brew gpgme install and got the message confirming the installation and the version.

我已经将gnupg.so文件放置在扩展路径中,并且还将extension = gnupg.so添加到了php.ini文件中.

I have placed the gnupg.so file in the extension path and also added extension=gnupg.so into the php.ini file.

我从infophp页面获得了扩展路径和特定php.ini的路径.重新启动Mamp之后,我仍然看不到gnupg或gpgme作为phpinfo的扩展,也不能在我的php代码中使用gnupg.
使用$gpg = new \gnupg();会给我说gnupg类不存在的错误.

I got the extension path and the specific php.ini's path from the infophp page.After restarting mamp, I still don't see gnupg or gpgme as extensions on phpinfo, neither I can use gnupg in my php code.
using $gpg = new \gnupg(); this gives me error saying gnupg class doesn't exist.

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'gnupg' not found

我尝试了另一种方法:我还从他们的网站上手动下载了gnupg和gpgme,并按照

I tried another approach:I also manually downloaded both gnupg and gpgme from their website extracted them ran following

./configure

./configure,

制造

sudo make install

sudo make install,

并能够再次成功安装,还请确保gnupg.so与phpinfo页面中显示的扩展路径相同,并且还将extension=gnupg.so添加到了phpinfo页面中出现的同一php.ini中(我在php.ini文件中的所有其他扩展名之后添加了extension = gnupg.so)

and was able to install successfully again, also made sure that gnupg.so is in the same path that shows up in phpinfo page for extension path and also added extension=gnupg.so to the same php.ini that appears in phpinfo page (I added the extension=gnupg.so right after all the other extensions in the php.ini file)

我正在使用:

mac os high sierra 10.13.3

mac os high sierra 10.13.3

php 7.1.12

php 7.1.12

模板4.4.1

gnupg 2.2.5(我通过brew install尝试了此版本)

gnupg 2.2.5 (I tried this version with brew install)

gnupg 1.4.0(我尝试从gnupg.org下载此版本)

gnupg 1.4.0 (I tried this version with downloading from gnupg.org)

gpgme 1.10.0

gpgme 1.10.0

我也想知道,在希望解决上述问题之后,我是否需要在php文件中包含任何内容才能使用gnupg?

I also would like to know, after hopefully fixing the above mentioned problems, do I need to include anything in my php file in order to use gnupg?

gnupg和gpgme有什么区别?为了加密php中的文件,我需要两者吗?

what are the differences between gnupg and gpgme? do I need both in order to encrypt a file in php?

如果我无法解决此问题,那么加密xml文件或包含文本数据的文件的另一种方法是什么?我需要将文件和FTP加密到另一台服务器,然后在那儿解密.

if I wasn't able to fix this what is another way to encrypt xml files or files containing text data? I need to encrypt the file and FTP to another server and decrypt it over there.

在此先感谢大家的帮助

推荐答案

我能够使用Pecl安装GnuPG来解决此问题.此链接也对我有很大帮助.

I was able to solve this issue using Pecl to install GnuPG.This link helped me a lot as well.

运行以下命令以安装库:

Run the following in order to install the library:

  1. sudo apt-get -y install gcc make autoconf libc-dev pkg-config
  2. sudo apt-get -y安装libgpgme11-dev
  3. sudo pecl安装gnupg
  4. 使用以下命令重新启动服务器:"service apache2 restart"或"sudo service phpX.Y-fpm-sp restart",其中x.y是php的major.minor版本.注意:有多种不同的方法可以重新启动系统,以使更改生效,因此请根据服务器和php版本来做自己的研究.
  5. 正如我在问题中解释的那样,请尝试找到正确的php.ini文件以将"extension = gnupg.so"添加到其中.您会发现php.ini的最常见的地方是:
    • /etc/php/7.2/apache2(您可以使用PHP版本而不是7.2)
    • /etc/php/7.2/cli(您可以使用PHP版本而不是7.2)

      更好的方法是从 phpinfo()
    • 中找出加载扩展的php.ini路径.
  1. sudo apt-get -y install gcc make autoconf libc-dev pkg-config
  2. sudo apt-get -y install libgpgme11-dev
  3. sudo pecl install gnupg
  4. Restart your server with: "service apache2 restart", or "sudo service phpX.Y-fpm-sp restart" where x.y is the major.minor version of your php. Note: there are multiple different ways to restart the system so the changes take effect, so please do your own research on how to do it depending on the server and your php version.
  5. As I've explained in my question, try to find the right php.ini file to add the "extension=gnupg.so" into. most common places you'll find your php.ini are:
    • /etc/php/7.2/apache2 (you can use your PHP version instead of 7.2)
    • /etc/php/7.2/cli (you can use your PHP version instead of 7.2)

      The better way is to find out the php.ini path that loads the extensions, from the phpinfo()

现在,使用以下命令验证一切是否正常:

Now Verify that it all went well with the following command:

  • "php -i | grep -i gnup"

如果一切正常,您将看到以下内容:

If everything is working as expected you'll see something like this:

  • /etc/php7.0-sp/conf.d/gnupg.ini,
    gnupg
    gnupg支持=>已启用
  • /etc/php7.0-sp/conf.d/gnupg.ini,
    gnupg
    gnupg support => enabled

这篇关于PHP Gnupg未在phpinfo()中显示为扩展名,我无法在php中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 17:21
查看更多