Create a cPanel Subdomain

This snippet will allow you to create a cPanel subdomain using PHP.
<?php

// your cPanel username
$cpanel_user = 'root';

// your cPanel password
$cpanel_pass = 'password';

// your cPanel skin
$cpanel_skin = 'x2';

// your cPanel domain
$cpanel_host = 'yourdomain.com';

// subdomain name
$subdomain = 'mysubdomain';

// create the subdomain

$sock = fsockopen($cpanel_host,2082);
if(!$sock) {
  print('Socket error');
  exit();
}

$pass = base64_encode("$cpanel_user:$cpanel_pass");
$in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$cpanel_host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";

fputs($sock, $in);
while (!feof($sock)) {
  $result .= fgets ($sock,128);
}
fclose($sock);

echo $result;

?>
If you want to delete the subdomain then change doadddomain.html to dodeldomain.html.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hi,

Great script, just what i was looking for, but I have a little problem, I have swaped doadddomain.html to dodeldomain.html to delete the subdomains but it wont work any help would be great.

I know this is an old post so not sure if it will get answered

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <i> <strong> <cite> <em> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <css>, <diff>, <drupal5>, <html>, <javascript>, <php>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.