Create subdomain using PHP (Cpanel)

 

Today i guide you create subdomain (cpanel) by PHP use xml api

<?php
require_once('/xmlapi.php');
$cpanelusr = 'username'; //username cpanel
$cpanelpass = 'password'; //password cpanel
$domainroot = 'rootdomain.com'; //root domain
$subdomain = 'subdomain'; //sudomain
$xmlapi = new xmlapi('xxx.xxx.xxx.xxx'); //link cpanel (can use ip)
create_subdomain($domain,$xmlapi); //
$xmlapi->set_port( 2083 ); //port cpanel
$xmlapi->password_auth($cpanelusr,$cpanelpass);
$xmlapi->set_debug(0); //output actions in the error log 1 for true and 0 false 
$result = $xmlapi->api1_query($cpanelusr, 'SubDomain', 'addsubdomain', array($subdomain, $domainroot,0,0, "/home/congtsco/public_html/{$subdomain}"));
?>

Now is library ( no need config anything )

https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php

Leave a Reply