1. Go to this page and download the library: Download socylist/acmecert 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/ */
socylist / acmecert example snippets
$handler=function($opts){
// Write code to setup the challenge token here.
// Return a function that gets called when the challenge token should be removed again:
return function($opts){
// Write code to remove previously setup challenge token.
};
};
$ac->getCertificateChain(..., ..., $handler);
$days=$ac->getRemainingDays('file://'.'fullchain.pem'); // certificate or certificate-chain
if ($days>30) { // renew 30 days before expiry
die('Certificate still good, exiting..');
}
// get new certificate here..
$ac->loadAccountKey('file://'.'account_key.pem');
$domain_config=array(
'example.com'=>array('challenge'=>'http-01','docroot'=>'/var/www/vhosts/example.com'),
'*.example.com'=>array('challenge'=>'dns-01'),
'test.example.org'=>array('challenge'=>'tls-alpn-01')
);
$handler=function($opts) use ($ac){
switch($opts['config']['challenge']){
case 'http-01': // automatic example: challenge directory/file is created..
$fn=$opts['config']['docroot'].$opts['key'];
@mkdir(dirname($fn),0777,true);
file_put_contents($fn,$opts['value']);
return function($opts) use ($fn){ // ..and removed after validation completed
unlink($fn);
};
break;
case 'dns-01': // manual example:
echo 'Create DNS-TXT-Record '.$opts['key'].' with value '.$opts['value']."\n";
readline('Ready?');
return function($opts){
echo 'Remove DNS-TXT-Record '.$opts['key'].' with value '.$opts['value']."\n";
};
break;
case 'tls-alpn-01':
$cert=$ac->generateALPNCertificate('file://'.'some_private_key.pem',$opts['domain'],$opts['value']);
// Use $cert and some_private_key.pem(<- does not have to be a specific key,
// just make sure you generated one) to serve the certificate for $opts['domain']
// This example uses an included ALPN Responder - a standalone https-server
// written in a few lines of node.js - which is able to complete this challenge.
// store the generated verification certificate to be used by the ALPN Responder.
file_put_contents('alpn_cert.pem',$cert);
// To keep this example simple, the included Example ALPN Responder listens on port 443,
// so - for the sake of this example - you have to stop the webserver here, like:
shell_exec('/etc/init.d/apache2 stop');
// Start ALPN Responder (