Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Install a pure PHP alternative

This guide explains how to use GnuPG / PGP with PHP on a Cloud Server using a "pure PHP" alternative, following the obsolescence of the native extension.

 

Preamble

  • The system extension PHP_GnuPG is no longer maintained by the PHP community, so it is no longer available on recent environments.
  • There are two main "pure PHP" alternatives (installable via Composer) to continue signing or encrypting your data securely.

 

Option 1: Crypt_GPG (recommended)

This library is a "wrapper": it uses the gpg binary already installed on your Cloud Server. It is the most robust solution and the closest to the old extension.

To install the library in your project, connect via SSH and run the following command at the root of your site:

composer require pear/crypt_gpg

Here is how to use the library to encrypt a message. Unlike the old extension, the approach here is object-oriented:

<?php
require_once 'vendor/autoload.php';

try {
    // Initialisation de l'objet GPG
    $gpg = new Crypt_GPG();

    // Spécifiez l'email correspondant à la clé publique importée sur le serveur
    $gpg->addEncryptKey('contact@exemple.com');

    $message = "Ceci est un message secret.";
    $enveloppe = $gpg->encrypt($message);

    echo $enveloppe;
} catch (Exception $e) {
    echo "Erreur : " . $e->getMessage();
}

 

Option 2: OpenPGP.php (independent)

This library is entirely written in PHP. It does not depend on the gpg software installed on the server, which ensures total portability of your code. Installation:

composer require singpolyma/openpgp-php

Usage example:

<?php
require_once 'vendor/autoload.php';
// La logique ici utilise directement les classes de la bibliothèque 
// pour manipuler les paquets OpenPGP sans appel système.

  

⚠️ For additional help contact a partner or launch a free call for tenders — also discover the role of the host.


Has this FAQ been helpful?