skip to Main Content

i am searching a lot here

https://documentation.cpanel.net/display/SDK/Guide+to+cPanel+API+2

https://documentation.cpanel.net/display/SDK/Guide+to+cPanel+API+1

but didn’t found any correct way. what my requirement is i need to host a domain on my server programmatically, where my clients provide me its domain name (ex: test.com) via a form and when he submit that form, i will set a wordpress site for it using that domain. Currently i setup a subdomain programmatically using cpanel api, what my requirement here is hosting a domain on my server and i have to do this using api.

2

Answers


  1. To connect with cpanel, you will be needed cpanel main domain, cpanel username and cpanel password. You will get connected with cpanel and then can easily create new addon domains. Once you get created addon domain then you can use individual addon domain to manage each domain specifically.

        require_once '../components/xmlapi.php';
    
        $xmlapi = new xmlapi($licence['cpanel_domain']);
        //checking authentication of the cpanel
        $xmlapi->password_auth($licence['username'],$licence['password']);
    
        $xmlapi->set_port(Yii::$app->params['domainPort']);
    
        $result = $xmlapi->api1_query($licence['password'], 'CustInfo', 'getemail', array());   
    
        // Add the "addondomain.com" addon domain.
    
        $api2args = array(
             'dir'            => 'addondomain/home/dir', 
             'newdomain'      => 'addondomain.com', 
             'subdomain'      => 'subdomain',
        );
    
        $add_addon = $xmlapi->api2('AddonDomain', 'addaddondomain', $api2args);
    
    Login or Signup to reply.
  2. Above I have suggested the way to create addon domain on a cpanel.
    Hereunder is the code to generate new cpanel account on WHM or server

    $xmlapi = new xmlapi($reseller->url);
    //checking authentication of the cpanel
    $xmlapi->password_auth($reseller->username, $reseller->password);                                                   
    $xmlapi->set_port(2087);
    $xmlapi->set_output('json');
    
    $conf = array("username"=>$username,"password"=>$password,"domain"=>$domain,"pkgname"=>$package,"contactemail"=>$contactemail,"cpmod"=>"x3");
    
    $result = json_decode($xmlapi->createacct($conf));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search