Create subdomains using PHP?


<title>create a subdomain</title>
<form name “form1” method “post” action “addsubdomain.php”>
<h1>create Sub Domains</h1>
Sub Domain Name : <input type “text” name “subdomain”><br />
<input type “submit” name “Submit” value “Submit”>



ini_set(‘display_errors’ 1);

$host “”; // your domain name without the www
$port 2082;
$path “/frontend/x/subdomain/doadddomain.html?domain “.$_POST[‘subdomain’].”&rootdomain “.$host; //or .dll etc. for authnet etc.

// these lines are changed
$cpaneluser “username”;
$cpanelpass “pass”;
$authstr “$cpaneluser:$cpanelpass”;

// Setup the Auth String
$pass base64_encode($authstr);

$fp fsockopen($host $port $errno $errstr $timeout 30);

//error tell us
echo “$errstr ($errno)n”;


//send the server request

fputs($fp “POST $path HTTP/1.1rn”);
fputs($fp “Host: $hostrn”);
fputs($fp “Authorization: Basic $pass rn”);
fputs($fp “Content-type: application/x-www-form-urlencodedrn”);
fputs($fp “Content-length: “.strlen($poststring).”rn”);
fputs($fp “Connection: closernrn”);
fputs($fp $poststring . “rnrn”);

// Remove this to stop it from displaying the output fron the CPanel
//loop through the response from the server
while(!feof($fp)) {
echo fgets($fp 4096);

while(!feof($fp)) { fgets($fp 4096); }
//close fp – we are done with it


  1. In you main httpd.conf add the following line at the bottom:Include /path/to/subdomains.conf

file name subdomains.conf

@mkdir ( /path/to/subdirectory/ .$name );

  1. $vhost
  2. ServerAdmin
  3. DocumentRoot /path/to/subdirectory/ .$name.
  4. ServerName .$name.
  5. ErrorLog /path/to/logs/ .$name. _error_log
  6. ;
  7. $fo fopen ( /path/to/subdomains.conf a );
  8. $fw fwrite ( $fo $vhost );
  9. fclose ( $fo );


Bookmark and Share
  1. November 22nd, 2009
    Trackback from : Trackback

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: