PHP How To Install SSL on Subdomain via cPanel API

Reading Time: 4 minutes

Inside this article we will see the concept i.e PHP How To Install SSL on subdomain via cPanel API. Article contains classified information about SSL installation on subdomain.

To install SSL either on domain or subdomain we have several ways. We can use cPanel UI to install SSL into sites. Or we can use cPanel APIs for it. In this tutorial we will how to consume cPanel SSL API to install SSL on wildcard subdomains.

Suppose we have a domain, Example: Already we have SSL installed on it. Now, we want to add or install SSL on these subdomains. Example:,, etc.

Wilcard Domains be like – *

Learn More –

Let’s get started.

Application Programming

In this article, we will create a single file called install-ssl.php. Inside this we will code to to install SSL on wildcard subdomains.

Before working on code you need these –

  • cPanel username
  • cPanel password
  • cPanel domain name
  • cPanel PORT
  • Either on all wildcard subdomain or select any one.
  • SSL Certificate Keys
  • cPanel XML API

Downlad cPanel XML API

Open install-ssl.php file and write this complete code into it.


include './xmlapi.php';

// cPanel credentials
$username = "CPANEL_USERNAME";
$password = "CPANEL_PASSWORD";
$cpanelDomain = "CPANEL_DOMAIN_URL"; //
$domainPort = 2083; // DEFAULT
$sslForDomain = "YOUR SUBDOMAIN"; //

// SSL Certificate Keys
$crt1 = "-----BEGIN CERTIFICATE-----

$key = "-----BEGIN RSA PRIVATE KEY-----

$crt2 = "-----BEGIN CERTIFICATE-----

// cPanel APIs - Authentication
$xmlapi = new \xmlapi($cpanelDomain);
$xmlapi->password_auth($username, $password);
$api2args = array();
$result = $xmlapi->api2_query($password, 'CustInfo', 'contactemails', $api2args);
$result = json_decode($result);

// echo "<pre>";
// print_r($result);
// die;

try {
    // Web server certificate SSL Upload
    $api2args = array(
        'domain' => $sslForDomain,
        'cert' => $crt1,
        'key' => $key,
        'cabundle' => $crt2,
    $result = $xmlapi->uapi_query($username, 'SSL', 'install_ssl', $api2args);
    $result = json_decode($result);

    echo "<pre>";
} catch (ErrorException $ex) {

    echo "<pre>";

Application Testing


Open URL into browser.

URL: http://localhost/ssl/install-ssl.php

Download Complete Source Code –

We hope this article helped you to learn PHP How To Install SSL on Subdomain via cPanel API in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more