Search code examples
ssl-certificatelets-encrypt

Automating LetsEncrypt Certificate Installation on shared server


Is it possible to programmatically installing LetsEncrypt Certificate on shared server, by using some opensource tool or PHP. Currently I'm generating Certificate on windows machine with "letsencrypt-win-simple" tool with W option which uses webdav to authenticate server. Certificate are generated locally in my windows machine and I've to configure it manually through cpanel every month.

Is it any possible automation for this process on certificate installation?


Solution

  • You can use Cpanel's API to install the new certificate. Here is a Linux example, but curl exists for Windows as well. You would need to change the paths in this script though:

    domain='example.org'
    ledir="/etc/letsencrypt/live/$domain"
    cabundle="$ledir/chain.pem"
    crt="$ledir/cert.pem"
    key="$ledir/privkey.pem"
    
    cpanel_host='cpanel.example.com:2083'
    cpanel_user=''
    
    curl -u "$cpanel_user"\
     "$cpanel_host/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SSL&cpanel_jsonapi_func=installssl&cpanel_jsonapi_user=$cpanel_user"\
     -d "domain=$domain" --data-urlencode "cabundle@$cabundle" --data-urlencode "crt@$crt" --data-urlencode "key@$key"
    

    This will still ask for your password. But it is possible to provide Curl with the password as well: curl -u "user:password" ...