PHP Startup: Unable to load dynamic library 'gnupg.so' (tried: /opt/bref/extensions/gnupg.so (libgpgme.so.11: cannot open shared object file: No such file or directory)
When using the gnupg-php-82 this error message appears in the Cloudwatch logs for the Lambda function.
We will need more details to help.
I've been digging into it and I think I have found the issue although not the solution yet. The problem is that libgpgme.so.11 and libassuan.so.0 aren't in any of the library paths. I created a layer that added them which appears to work but then has a libc version mismatch error.
It's easy to replicate using this serverless.yml:
service: PGP-Encrypt
provider: name: aws region: us-east-1
plugins: - ./vendor/bref/bref - ./vendor/bref/extra-php-extensions
functions: Encrypt: handler: test.php layers: - ${bref-extra:gnupg-php-81} description: '' runtime: php-81-fpm timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds) events: - httpApi: '*'
package: patterns: - '!node_modules/' - '!tests/'
And the test.php file from the repo in the gnupg layer
Similar issue in PHP 8.3. A warning instead of initial error was reported.
Warning: PHP Startup: Unable to load dynamic library 'gnupg.so' (tried: /opt/bref/extensions/gnupg.so (libgpgme.so.11: cannot open shared object file: No such file or directory), /opt/bref/extensions/gnupg.so.so (/opt/bref/extensions/gnupg.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Here are my project files.
composer.json:
{
"require": {
"bref/bref": "^2.1.12",
"bref/extra-php-extensions": "^1.4.0"
}
}
serverless.yml
service: bref-demo
provider:
name: aws
region: us-east-1
plugins:
- ./vendor/bref/bref
- ./vendor/bref/extra-php-extensions
functions:
hello:
handler: index.php
description: ''
runtime: php-83
layers:
- ${bref-extra:gnupg-php-83}
# Exclude files from deployment
package:
patterns:
- '!tests/**'
index.php:
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
return function ($event) {
phpinfo();
return 'Hello ' . ($event['name'] ?? 'world');
};
Fixed in the latest release.