1. Go to this page and download the library: Download tomcan/acmeclient library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomcan / acmeclient example snippets
$httpClient = \Symfony\Component\HttpClient\HttpClient::create();
$acmeClient = new \TomCan\AcmeClient\AcmeClient($httpClient, 'https://acme-staging-v02.api.letsencrypt.org/directory');
// Create new account object
/** @var AccountInterface $account */
$account = new Account('[email protected]', null, null);
$acmeClient->getAccount($account);
// Example for your convenience only.
// save Account after having called $acmeClient->getAccount($account) to create the account
$acmeClient->getAccount($account);
file_put_contents('/path/to/account.json', json_encode(['email' => $account->getEmail(), 'url' => $account->getEmail(), 'key' => $account->getKey()]));
// re-loading the account on later requests
$accountData = json_decode(file_get_contents('/path/to/account.json));
$account = new Account($accountData->email, $accountData->url, $accountData->key);
$acmeClient->getAccount($account);
// example of using the http-01 HTTP challenge
$challenges = [];
foreach ($authorizations as $authorization) {
$a[] = $authorization;
foreach ($authorization->getChallenges() as $challenge) {
if ($challenge->getType() == 'http-01') {
$challenges[] = $challenge;
// e.g. write file to documentroot of webserver
file_put_contents('/path/to/documentroot/.well-known/acme-challenge/'.$challenge->getToken(), $challenge->getValue());
}
}
}
$result = $acmeClient->validate($authorizations, $challenges);