LetEncrypt Install Certificate

Use the LetEncrypt Install Certificate API to install the certificate issued by Let’s Encrypt. Let’s Encrypt is a free, automated, and open Certificate Authority (CA). It will issue certificate for your domain names for free after domain name verification and Virtualizor from version 2.8.8 onward has integrated this feature.

The API response will contain “done” as the message “Configuration saved successfully” after the certificate is installed successfully.

For more information, you can refer this Let’s Encrypt Certificate Installation Guide.

HTTP Request

https://hostname:4085/index.php?act=letsencrypt

Parameters

NameMethodValueDescriptionRequired
actGETletsencryptThe action will return the certificate config and done as “Configuration saved successfully”Yes
optPOSTtextFor installing the certificate this value should be “save_crt”Yes
primary_domainPOSTtextThe primary domain will be required to point the ssl to the correct domainYes
contact_emailPOSTtextThe users email who will be installing the certificateYes
key_sizePOSTIntRefers to privake key size in bits i.e the strength of the private key, refer below table for valid valuesYes
renew_daysPOSTIntThe day for the certificate’s expirationYes
stagingPOST1/0If set then Lets Encrypts test certificate will be installed on the systemNo
enable_forcePOST1/0If the certificate needs to be re-installed on the system then this option should be enabledYes

Languages

( 2048 | 3072 | 4096 | 8192 | ec-256 | ec-384 )

Sample Code

<?php

    require_once('/usr/local/virtualizor/sdk/admin.php');

    $key =  'your_api_key';
    $pass = 'your_api_pass';
    $ip = 'your_server_ip';

    $admin = new Virtualizor_Admin_API($ip, $key, $pass);

    $post = array();
    $post['opt'] = 'save_cfg';
    $post['primary_domain'] = 'hostname';
    $post['contact_email'] = 'test@test.com';
    $post['key_size'] = 2048;
    $post['renew_days'] = 80;
    $post['staging'] = 0;
    $post['enable_force'] = 1; 

    $output = $admin->letsencrypt($post);

    print_r(json_encode($output));
?>

Output

{
    "title": "LetsEncrypt",
     "done": "Configuration saved successfully",
    "crt_config_options": {
        "crt_save_cfg_frm": {
            "inputs": {
                "primary_domain": {
                    "type": "text",
                    "value": "hostname"
                },
                "contact_email": {
                    "type": "text",
                    "value": "test@test.com"
                },
                "key_size": {
                    "type": "select",
                    "value": "2048"
                },
                "renew_days": {
                    "type": "text",
                    "value": "80"
                },
                "staging": {
                    "type": "checkbox",
                    "value": "0"
                },
                "enable_force": {
                    "type": "checkbox",
                    "value": "1"
                }
            }
        }
    },
    "crt_details": {
        "crt_domain": "",
        "crt_san": "",
        "crt_issuer": "",
        "crt_serialno": "",
        "crt_valid_from_time": "",
        "crt_valid_to_time": "",
        "next_renew": "",
        "crt_installed": "No"
    },
    "actid": "3413",
    "logs": "null",
    "timenow": "1478743086",
    "time_taken": "1.608"
}
Was this helpful to you?