title: Create subdomain of addon domain
body: <p>How can I create a subdomain of the addon domain using PHP programmatically?</p>
  
  <p>My primary domain is example.com</p>
  
  <p>an addon domain is example2.com</p>
  
  <p>Now I want to create test.example2.com using PHP. How can I create this subdomain?</p>
  
  <p>I tried the following code, but it always creates a subdomain of the primary domain.</p>
  
  <pre><code>function create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) 
      {
          $buildRequest = "/frontend/paper_lantern/subdomain/doadddomain.html?rootdomain=".$rootDomain."&amp;domain=".$subDomain."&amp;dir=example2.com/".$subDomain;
  
          $openSocket = fsockopen('localhost',2082);
          if(!$openSocket) 
          {
              return "Socket error";
              exit();
          }
  
          $authString = $cPanelUser.":".$cPanelPass;
          $authPass = base64_encode($authString);
          $buildHeaders  = "GET ".$buildRequest."\r\n";
          $buildHeaders .= "HTTP/1.0\r\n";
          $buildHeaders .= "Host:localhost\r\n";
          $buildHeaders .= "Authorization: Basic ".$authPass."\r\n";
          $buildHeaders .= "\r\n";
  
          fputs($openSocket, $buildHeaders);
          //echo $openSocket;
          while(!feof($openSocket)) 
          {
              fgets($openSocket,128);
          }
          fclose($openSocket);
  
  
      }
  $subDomain = 'test.example2.com';
  $cPanelUser = 'username';
  $cPanelPass = 'password';
  $rootDomain = 'http://www.exampe2.com/';
  
  create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain);
  </code></pre>