简体   繁体   English

PHP Gnupg未在phpinfo()中显示为扩展名,我无法在php中使用它

[英]PHP Gnupg is not showing up as an extension in phpinfo() and I can't use it in php

I have gnupg and gpgme installed using homebrew. 我使用自制软件安装了gnupg和gpgme。 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. 我还链接了这两个文件,并通过运行brew gnupg install和brew gpgme install来确保它们已安装并链接,并得到确认安装和版本的消息。

I have placed the gnupg.so file in the extension path and also added extension=gnupg.so into the php.ini file. 我已经将gnupg.so文件放在扩展路径中,并且还将extension = gnupg.so添加到了php.ini文件中。

I got the extension path and the specific php.ini's path from the infophp page. 我从infophp页面获得了扩展路径和特定php.ini的路径。 After restarting mamp, I still don't see gnupg or gpgme as extensions on phpinfo, neither I can use gnupg in my php code. 重新启动Mamp之后,我仍然看不到gnupg或gpgme作为phpinfo的扩展,我也不能在我的php代码中使用gnupg。
using $gpg = new \\gnupg(); 使用$gpg = new \\gnupg(); this gives me error saying gnupg class doesn't exist. 这给我一个错误,说gnupg类不存在。

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

I tried another approach: I also manually downloaded both gnupg and gpgme from their website extracted them ran following 我尝试了另一种方法:我还从他们的网站上手动下载了gnupg和gpgme,并提取了以下内容

./configure, 。/配置,

make, 使,

sudo make install, sudo make install,

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

I am using: 我在用:

mac os high sierra 10.13.3 Mac OS High Sierra 10.13.3

php 7.1.12 PHP 7.1.12

mamp 4.4.1 模板4.4.1

gnupg 2.2.5 (I tried this version with brew install) gnupg 2.2.5(我使用brew install尝试了此版本)

gnupg 1.4.0 (I tried this version with downloading from gnupg.org) gnupg 1.4.0(我尝试从gnupg.org下载此版本)

gpgme 1.10.0 gpgme 1.10.0

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

what are the differences between gnupg and gpgme? gnupg和gpgme有什么区别? do I need both in order to encrypt a file in php? 我是否都需要为了在php中加密文件?

if I wasn't able to fix this what is another way to encrypt xml files or files containing text data? 如果我无法解决此问题,还有什么方法可以加密xml文件或包含文本数据的文件? I need to encrypt the file and FTP to another server and decrypt it over there. 我需要加密文件和FTP到另一台服务器,然后在那儿解密。

Thank you all in advance for your help 预先感谢大家的帮助

I was able to solve this issue using Pecl to install GnuPG. 我能够使用Pecl安装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 须藤apt-get -y install gcc make autoconf libc-dev pkg-config
  2. sudo apt-get -y install libgpgme11-dev 须藤apt-get -y install libgpgme11-dev
  3. sudo pecl install gnupg sudo pecl安装gnupg
  4. Restart your server with: "service apache2 restart", or "sudo service phpX.Y-fpm-sp restart" where xy is the major.minor version of your php. 使用以下命令重新启动服务器:“ service apache2 restart”或“ sudo service phpX.Y-fpm-sp restart”,其中xy是php的major.minor版本。 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. 注意:有多种不同的方法可以重新启动系统,以使更改生效。因此,请根据服务器和php版本,自行研究如何执行此操作。
  5. As I've explained in my question, try to find the right php.ini file to add the "extension=gnupg.so" into. 正如我在问题中解释的那样,尝试找到正确的php.ini文件以将“ extension = gnupg.so”添加到其中。 most common places you'll find your php.ini are: 最常见的地方是php.ini:
    • /etc/php/7.2/apache2 (you can use your PHP version instead of 7.2) /etc/php/7.2/apache2(您可以使用PHP版本而不是7.2)
    • /etc/php/7.2/cli (you can use your PHP version instead of 7.2) /etc/php/7.2/cli(您可以使用PHP版本而不是7.2)

      The better way is to find out the php.ini path that loads the extensions, from the phpinfo() 更好的方法是从phpinfo()中找出加载扩展的php.ini路径。

Now Verify that it all went well with the following command: 现在,使用以下命令验证是否一切正常:

  • "php -i | grep -i gnup" “ 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, /etc/php7.0-sp/conf.d/gnupg.ini,
    gnupg gnupg
    gnupg support => enabled gnupg支持=>已启用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM