How to Use Let's Encrypt for Shared Hosting Cpanel without Let's Encrypt Extension

First of all, Yes!, you can have a free SSL certificate installed on your CPanel hosted shared server! The process was tedious, but now is one cron job away, for unlimited certification freedom. It fetches and installs the certificates for the configured domains(s) or subdomain(s). LetsEncrypt v2 protocol supported.

Installation

  • Clone this repo , and run composer install
  • Zip and upload the folder to your cpanel /home/username directory.
  • Unzip and rename the folder .sslscript, I advise not to put it inside the public directory, although all sensitive folders are protected with .htaccess rules.
  • Move ressl.php file to public folder, so you can run the script from url or cron job.
  • open ressl.php and change the path of .sslscript

Edit the config.php file or create a new file and name it like config.mydomain.php. This way you can have multiple configurations.

return [
    'testing' => false,
    'minDays' => 15, // Minimum days to wait before requesting new certificates
    'cpanel' => [
        'host' => 'https://cpanelhost.com:2083', // 'https://mydomain.com:2083' // ip or domain complete with its protocol and port
        'username' => '', // CPanel username
        'password' => '', // CPanel user password or comment and use api token
        // 'token' => '' // CPanel api access token, use this instead of password, comment the above line
    ],
    'accounts' => [
        [
            'email' => 'info@mydomain.com',
            'publicPath' => '../public_html', // related to the script location, no trailing /
            'domains' => ['mydomain.com', 'www.mydomain.com'],
            'disabled' => false,
        ],
    ]
];

you can add a new array on accounts instead of making a new config.newdomain.php file like this :

    'accounts' => [
        [
            'email' => 'info@mydomain.com',
            'publicPath' => '../public_html', // related to the script location, no trailing /
            'domains' => ['mydomain.com', 'www.mydomain.com'],
            'disabled' => false,
        ],
        [
            'email' => 'info@sub.mydomain.com',
            'publicPath' => '../sub.mydomain.com', // related to the script location, no trailing /
            'domains' => ['sub.mydomain.com', 'www.sub.mydomain.com'],
            'disabled' => false,
        ],
    ]

Usage :

go to mydomain.com/ressl.php to run script and issue your ssl certificate

Go to the cron job tab on your CPanel and add the command to run every week.

php -q /home/username/.sslscript/index.php config=mydomain or php -q /home/username/.sslscript/index.php if you have only one config.php file

this cron will run every week to renew the expired ssl, it will loop on accounts array of your domains in config file