PHP code example of takuya / php-letencrypt-acme-dns
1. Go to this page and download the library: Download takuya/php-letencrypt-acme-dns 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/ */
takuya / php-letencrypt-acme-dns example snippets
/** ********
* Prepare
*/
use Takuya\LEClientDNS01\Account;
$cf_api_token = getenv( 'LE_CLOUDFLARE_TOKEN' );
$your_email = getenv( 'LE_EMAIL' );
$domain_names = ["www.your-domain.tld",'*.www.your-domain.tld'];
$account = new Account( $your_email );
/** ********
* Order certificate.
*/
$dns = new CloudflareDNSPlugin( $cf_api_token, base_domain($domain_names[0]) );
$cli = new LetsEncryptAcmeDNS( $account );
$cli->setDomainNames( $domain_names );
$cli->setAcmeURL( LetsEncryptACMEServer::PROD );
$cli->setDnsPlugin( $dns );
$cert_and_a_key = $cli->orderNewCert();
/** ********
* Save in your own way.
*/
$owner_pkey = $account->private_key;
$cert_pem = $cert_and_a_key->cert();
$cert_pkey = $cert_and_a_key->privKey();//domain pkey, not an owner's pkey.
$full_chain = $cert_and_a_key->fullChain();
$pkcs12 = $cert_and_a_key->pkcs12('enc pass');
$cert_info = new SSLCertificateInfo( $cert_and_a_key->cert(); );
// set dns plugin per Domain.
$cli = new LetsEncryptAcmeDNS( 'priv_key_pem', '[email protected]' );
$dns_plugin_1 = new CloudflareDNSPlugin( 'cloudflare_token', 'example.tld' );
$dns_plugin_2 = new YourOwnPlugin( 'your_own_key', 'example.biz' );
$cli->setDnsPlugin( $dns_plugin_1, 'example.tld' );
$cli->setDnsPlugin( $dns_plugin_2, 'example.biz' );
class YourOwnPlugin extends DNSPlugin{
}
class YourOwnPlugin extends DNSPlugin{
public function addDnsTxtRecord ( $domain, $content ): bool;{
// TODO: write your way to add TXT Record for ACME challenge.
}
public function removeTxtRecord ( $domain, $content ): bool{
// TODO: Write in your way, how to remove TXT Record , after ACME.
}
}