Hướng dẫn php gnupg.dll for windows

I want to use PGP in my PHP project, using XAMPP on Windows.

Nội dung chính

  • Not the answer you're looking for? Browse other questions tagged php apache xampp gnupg openpgp or ask your own question.
  • Installation
  • Documentation
  • Does GnuPG work on Windows?
  • How do I download GnuPG on Windows?
  • What is GnuPG package?

When I run this code:

$public_key = "PGP Public Key";
$gpg = new gnupg();
$key = $gpg->import($public_key);
$gpg->addencryptkey($key['fingerprint']);
$enc = $gpg->encrypt("Hello Stackoverflow!");
$gpg->clearencryptkeys();
echo nl2br($enc);

I get an error message telling me that I have to install the GNUPG extension in my Apache server.

How do I install GNUPG for XAMPP on Windows? I only found solutions for Linux.

janw

7,4969 gold badges34 silver badges56 bronze badges

asked Dec 9, 2017 at 13:05

As per the official php-gnupg repository, there's no extension for Windows yet.

The extension is not currently supported on Windows due to unavailable GpgME library builds that would be supported by PHP.

answered May 20, 2021 at 8:18

Not the answer you're looking for? Browse other questions tagged php apache xampp gnupg openpgp or ask your own question.

PHP GnuPG

The php-gnupg is a wrapper for GpgME library that provides access to GnuPG.

Installation

Linux

Before starting with installation of this extensions, the GpgME library has to be installed. It has got installation packages on the most Linux distributions. The minimal version of GpgME that is supported is 1.3.0. The extension supports GnuPG version 1 and 2.

Of course PHP has to be installed too. The minimal version that is supported is 5.3.2.

PECL

This extension is available on PECL.

$ sudo pecl install gnupg

Manual Installation

It's important to have a git installed as it's necessary for recursive fetch of phpc.

First clone recursively the repository

git clone --recursive https://github.com/php-gnupg/php-gnupg.git

Then go to the created directory and compile the extension. The PHP development package has to be installed (command phpize must be available).

cd php-gnupg
phpize
./configure
make
sudo make install

Finally the following line needs to be added to php.ini

or for PHP 8+ it's just

Windows

The extension is not currently supported on Windows due to unavailable GpgME library builds that would be supported by PHP.

Documentation

The extension documentation is now available in the PHP-Manual: http://php.net/manual/en/book.gnupg.php

Mahbub Kabir

8 years ago

I tried followings on Debian Squeeze and it worked fine

apt-get install libgpgme11-dev
pecl install gnupg

create a new file under conf.d folder and add following lines

; configuration for gnupg module
extension=gnupg.so

Reload apache configuration
/etc/init.d/apache2 reload

Check PHP Info and you should see gnupg

Hope this helps.

Dominik Sommer

9 years ago

For Ubuntu 12.04, these are the steps:
1. Install packages: gnupg libgpg-error-dev libassuan-dev
2. Download GPGME library from ​http://www.gnupg.org/download/index.en.html#gpgme
3. Extract, then run
   configure
   make && sudo make install
4. Install PECL extension
   sudo pecl install gnupg
5. Add to php.ini
   extension=gnupg.so

frozenfire at php dot net

10 years ago

Here are instructions for how to resolve the issue where you encounter this error:

/usr/include/gpgme.h:80:2: error: #error GPGME was compiled with _FILE_OFFSET_BITS = 64, please see the section "Largefile support (LFS)" in the GPGME manual.

This is a result of the gnupg extension currently lacking largefile support. The solution is fairly simple.

pecl download gnupg
tar -zxf gnupg-1.3.2.tgz
cd gnupg-1.3.2

Open the file config.m4 in an editor, and add "AC_SYS_LARGEFILE" to a new line at the very end of the file, then save.

phpize
./configure
make
make install

Now simply add extension=gnupg.so to your php.ini, and the extension should work.

Mr T

9 months ago

On Ubuntu 20, this is provided via `php-gnupg` (or with a specific version `php8.1-gnupg`)

To install:

`apt install php-gnupg`

mk at wintermute dot at

13 years ago

Quick installation guide on Fedora 10:

Needed:
- c++ compiler
- php-pear
- gnupg
- libgpg-error
- gpgme
- gpgme-devel
- php-devel

Install with:
$ pecl install gnupg

Add an entry to /etc/php.ini:
extension=gnupg.so

Restart Apache > you're done.

Jane Doe

9 years ago

Hi -

By default on Ubuntu 12.04 LTS gnupg needs to write to .gnupg in the home directory of the user running PHP (so for a web site this is www-data). You might need to make a ~/.gnupg for www-data and chown/chmod it correctly or everything will fail.

Heath

11 years ago

On Debian 5.05 (Lenny) I needed to install libgpgme11-dev

sma dot azar at gmail dot com

13 years ago

After spending so much time I could only install it on Linux and not Windows. There is very little instructions on the net about installation of this module, so I am going to write a small instructions that should help a straightforward installation on Linux without so much trouble.

Step 1: you will need a C++ compiler on your machine. For being sure try this command in the terminal:
sudo apt-get install g++
?>
Obviously you need GnuPG itself, so try:
sudo apt-get install gnupg
?>
Step 2: you will need "Libgpg-Error" downloaded and installed on your machine.
2-1: Download the code from http://www.gnupg.org/download/#libgpg-error
2-2: Extract it to a directory. In the terminal, change the directory to the Libgpg-error directory.
2-3: Configure the package for building and installation with below command:
./configure
?>
2-4: In the same directory make it with below command:
sudo make
?>
2-5: In the same directory install it with below command:
sudo make install
?>

Step 3: you will need "GnuPG Made Easy" (GPGME) downloaded and installed on your machine. Some sources will tell you that you can "apt-get install" it, but actually you cannot. So do it like the latter:
3-1: Download the source code from http://www.gnupg.org/download/#gpgme
3-2: Extract it to a directory. In the terminal, change the directory to the GPGME directory.
3-3: Configure the package for building and installation with below command:
./configure
?>
3-4: In the same directory make it with below command:
sudo make
?>
3-5: In the same directory install it with below command:
sudo make install
?>

Step 4: Given that you have a LAMP server already and have php installed, you will need "pear" and "php source codes". To add them use below commands:
sudo apt-get install php5-dev
sudo apt
-get install php-pear
?>

Step 5: Now you can install GNU Privacy Guard for php using PECL command:
sudo pecl install gnupg
?>

Does GnuPG work on Windows?

You can get GnuPG (also known as GPG) on Windows by downloading the small installer from the GnuPG download page. Click on download next to “Simple installer for GnuPG modern” which will download the GPG installer.

How do I download GnuPG on Windows?

Go to the GnuPG website to download the software: https://gnupg.org/download/index.html. Scroll to GnuPG Binary Releases. For the Windows OS, select the Download Sig link either for Simple Installer for the Current GnuPG or Simple Installer for GnuPG 1.4. Select Run and follow the steps to install the software.

What is GnuPG package?

GnuPG is a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP). GnuPG allows you to encrypt and sign your data and communications; it features a versatile key management system, along with access modules for all kinds of public key directories.