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

别等时光非礼了梦想. 提交于 2020-01-24 00:45:09

问题


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.

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

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

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

./configure,

make,

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)

I am using:

mac os high sierra 10.13.3

php 7.1.12

mamp 4.4.1

gnupg 2.2.5 (I tried this version with brew install)

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

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?

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

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.

Thank you all in advance for your help


回答1:


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 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 support => enabled


来源:https://stackoverflow.com/questions/48958165/php-gnupg-is-not-showing-up-as-an-extension-in-phpinfo-and-i-cant-use-it-in-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!