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 an Infomaniak Cloud Server, following the obsolescence of the native extension (pure PHP alternatives or modern wrappers are preferred).
Preamble
- The system extension
PHP_GnuPGis no longer maintained by the PHP community and is therefore no longer available on recent environments. - Two main alternatives in Pure PHP (installable via Composer) allow you to continue signing or encrypting your data securely.
- If needed, local partners referenced by Infomaniak can handle these procedures: launch a free call for tenders; they handle everything, freeing you from technical details — also discover the role of the host.
Option 1: Crypt_GPG (Recommended)
This library acts as a wrapper: it communicates directly with the gpg binary installed on your Cloud Server. It is the most performant and stable solution.
To install it, connect via SSH and run this command at the root of your project:
# Install the PEAR Crypt_GPG package via Composer
composer require pear/crypt_gpgExample of usage to encrypt a message (object-oriented approach):
<?php
require_once 'vendor/autoload.php';
try {
// Initialize the GPG object
$gpg = new Crypt_GPG();
// Set the recipient email (must match a public key already imported on the server)
$gpg->addEncryptKey('contact@example.com');
$message = "This is a secret message.";
// Encrypt the data
$enveloppe = $gpg->encrypt($message);
echo $enveloppe;
} catch (Exception $e) {
// Handle potential encryption errors
echo "Error: " . $e->getMessage();
}
Option 2: OpenPGP.php (Independent)
This library is entirely written in PHP. Its main advantage is that it does not depend on the server's gpg binary, ensuring total portability of your code across different environments.
# Install the OpenPGP.php library
composer require singpolyma/openpgp-phpExample of basic structure:
<?php
require_once 'vendor/autoload.php';
// Use the library classes to handle OpenPGP packets
// directly in PHP without system calls to the GPG binary.
// Example: $msg = OpenPGP_Message::parse(OpenPGP::unarmor($data));Link to this FAQ:
Has this FAQ been helpful?