LEClient
An easy-to-use PHP ACME v2 client library, designed to be used with LetsEncrypt.
Install / Use
/learn @yourivw/LEClientREADME
LEClient
PHP LetsEncrypt client library for ACME v2. The aim of this client is to make an easy-to-use and integrated solution to create a LetsEncrypt-issued SSL/TLS certificate with PHP. The user has to have access to the web server or DNS management to be able to verify the domain is accessible/owned by the user.
Current version
The current version is 1.2.2
Getting Started
These instructions will get you started with this client library. If you have any questions or find any problems, feel free to open an issue and I'll try to have a look at it.
Also have a look at the LetsEncrypt documentation for more information and documentation on LetsEncrypt and ACME.
Prerequisites
The minimum required PHP version is 5.2.0. Version 7.1.0 is required for EC keys. The function generating EC keys will throw an exception when trying to generate EC keys with a PHP version below 7.1.0.
Version 1.0.0 will be kept available, but will not be maintained.
This client also depends on cURL and OpenSSL.
Installing
Using composer:
composer require yourivw/leclient
It is advisable to cut the script some slack regarding execution time by setting a higher maximum time. There are several ways to do so. One is to add the following to the top of the page:
ini_set('max_execution_time', 120); // Maximum execution time in seconds.
Usage
The basic functions and its necessary arguments are shown here. An extended description is included in each class.
As of version 1.1.6, it is also possible to initiate the LEClient with a PSR-3 logger (\Psr\Log\LoggerInterface).
<br />Initiating the client:
use LEClient\LEClient;
$client = new LEClient($email); // Initiating a basic LEClient with an array of string e-mail address(es).
$client = new LEClient($email, LEClient::LE_STAGING); // Initiating a LECLient and use the LetsEncrypt staging URL.
$client = new LEClient($email, LEClient::LE_PRODUCTION); // Initiating a LECLient and use the LetsEncrypt production URL.
$client = new LEClient($email, true); // Initiating a LECLient and use the LetsEncrypt staging URL.
$client = new LEClient($email, true, $logger); // Initiating a LEClient and use a PSR-3 logger (\Psr\Log\LoggerInterface).
$client = new LEClient($email, true, LEClient::LOG_STATUS); // Initiating a LEClient and log status messages (LOG_DEBUG for full debugging).
$client = new LEClient($email, true, LEClient::LOG_STATUS, 'keys/'); // Initiating a LEClient and select custom certificate keys directory (string or array)
$client = new LEClient($email, true, LEClient::LOG_STATUS, 'keys/', '__account/'); // Initiating a LEClient and select custom account keys directory (string or array)
The client will automatically create a new account if there isn't one found. It will forward the e-mail address(es) supplied during initiation, as shown above.
<br />Using the account functions:
$acct = $client->getAccount(); // Retrieves the LetsEncrypt Account instance created by the client.
$acct->updateAccount($email); // Updates the account with new contact information. Supply an array of string e-mail address(es).
$acct->changeAccountKeys(); // Generates a new RSA keypair for the account and updates the keys with LetsEncrypt.
$acct->deactivateAccount(); // Deactivates the account with LetsEncrypt.
<br />
Creating a certificate order instance. If there is an order found, stored locally, it will use this order. Otherwise, it will create a new order. If the supplied domain names don't match the order, a new order is created as well. The construction of the LetsEncrypt Order instance:
$order = $client->getOrCreateOrder($basename, $domains); // Get or create order. The basename is preferably the top domain name. This will be the directory in which the keys are stored. Supply an array of string domain names to create a certificate for.
$order = $client->getOrCreateOrder($basename, $domains, $keyType); // Get or create order. keyType can be set to "ec" to get ECDSA certificate. "rsa-4096" is default value. Accepts ALGO-SIZE format.
$order = $client->getOrCreateOrder($basename, $domains, $keyType, $notBefore); // Get or create order. Supply a notBefore date as a string similar to 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss).
$order = $client->getOrCreateOrder($basename, $domains, $keyType, $notBefore, $notAfter); // Get or create order. Supply a notBefore and notAfter date as a string similar to 0000-00-00T00:00:00Z (yyyy-mm-dd hh:mm:ss).
<br />
Using the order functions:
use LEClient\LEOrder;
$valid = $order->allAuthorizationsValid(); // Check whether all authorizations in this order instance are valid.
$pending = $order->getPendingAuthorizations($type); // Get an array of pending authorizations. Performing authorizations is described further on. Type is LEOrder::CHALLENGE_TYPE_HTTP or LEOrder::CHALLENGE_TYPE_DNS.
$verify = $order->verifyPendingOrderAuthorization($identifier, $type); // Verify a pending order. The identifier is a string domain name. Type is LEOrder::CHALLENGE_TYPE_HTTP or LEOrder::CHALLENGE_TYPE_DNS.
$deactivate = $order->deactivateOrderAuthorization($identifier); // Deactivate an authorization. The identifier is a string domain name.
$finalize = $order->finalizeOrder(); // Finalize the order and generate a Certificate Signing Request automatically.
$finalize = $order->finalizeOrder($csr); // Finalize the order with a custom Certificate Signing Request string.
$finalized = $order->isFinalized(); // Check whether the order is finalized.
$cert = $order->getCertificate(); // Retrieves the certificate and stores it in the keys directory.
$revoke = $order->revokeCertificate(); // Revoke the certificate without a reason.
$revoke = $order->revokeCertificate($reason); // Revoke the certificate with a reason integer as found in section 5.3.1 of RFC5280.
<br />
Supportive functions:
use LEClient\LEFunctions;
LEFunctions::RSAGenerateKeys($directory, $privateKeyFile, $publicKeyFile); // Generate a RSA keypair in the given directory. Variables privateKeyFile and publicKeyFile are optional and have default values private.pem and public.pem.
LEFunctions::ECGenerateKeys($directory, $privateKeyFile, $publicKeyFile); // Generate a EC keypair in the given directory (PHP 7.1+ required). Variables privateKeyFile and publicKeyFile are optional and have default values private.pem and public.pem.
LEFunctions::Base64UrlSafeEncode($input); // Encode the input string as a base64 URL safe string.
LEFunctions::Base64UrlSafeDecode($input); // Decode a base64 URL safe encoded string.
LEFunctions::log($data, $function); // Print the data. The function variable is optional and defaults to the calling function's name.
LEFunctions::checkHTTPChallenge($domain, $token, $keyAuthorization); // Checks whether the HTTP challenge is valid. Performing authorizations is described further on.
LEFunctions::checkDNSChallenge($domain, $DNSDigest); // Checks whether the DNS challenge is valid. Performing authorizations is described further on.
LEFunctions::createhtaccess($directory); // Created a simple .htaccess file in the directory supplied, denying all visitors.
Filesystem Structure
LEClient stores account keys, certificate keys, certificates and order data in the filesystem. By default, the folder structure used will look like this, relative to your working directory:
keys/ Top-level LEClient folder
public.pem Your certificate’s public key
private.pem Your certificate’s private key
order A file used to store the order URL
fullchain.crt The full-chain certificate
certificate.crt The certificate
__account/ An internal folder for LEClient to store your account keys
public.pem Your ACME account’s public key
private.pem Your ACME account’s private key
.htaccess An automatically-generated .htaccess to prevent accidental exposure
You can customise these locations by passing values to the $certificateKeys and $accountKeys construction parameters when creating an LEClient.
Passing strings will change the location and name of the top-level LEClient folder, and the name of the Account Key folder. Note that when passing strings, the account key folder will always be a subfolder of the top-level folder, meaning that:
$client = new LEClient('email@example.com', LEClient::PRODUCTION, LEClient::LOG_OFF, 'path/to/my/key/folder/', 'my_account_folder');
will result in the following structure:
path/to/my/key/folder/
public.pem
…
my_account_folder/
public.pem
…
If you want to have more control over the exact locations the various files are stored in, you can instead pass arrays to the $certificateKeys and $accountKeys parameters. If you pass an array to one, you must pass arrays to both.
$client = new LEClient('email@example.com', LEClient::PRODUCTION, LEClient::LOG_OFF, [
'public_key' => 'path/to/public/key.pem', // Required
'private_key' => 'path/to/private/key.pem', // Require
Related Skills
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
ui-ux-pro-max-skill
59.8kAn AI SKILL that provide design intelligence for building professional UI/UX multiple platforms
