• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Script PHP for creating subdomain

JulienA26

New Pleskian
Hello,
I am trying to write a script PHP creating a subdomain on a server when executed (as well as doing other stuff, but that part work).
But, when I send my request to the server, the script, while it does create the subdomain, doesn't display anything upon execution (I have put a few echo in the script to check the advancement, and nothing appears).
The error message : Echec du chargement de la page Aucune donnée reçue.
Here is my code :

/**
* Returns DOM object representing request for creation of new subdomain named after the parameter
* @return DOMDocument
*/
function createSubdomain($nom)
{
$xmldoc = new DomDocument('1.0', 'UTF-8');
$xmldoc->formatOutput = true;
$packet = $xmldoc->createElement('packet');
$packet->setAttribute('version', '1.5.2.0');
$xmldoc->appendChild($packet);
$subdomain = $xmldoc->createElement('subdomain');
$packet->appendChild($subdomain);
$add = $xmldoc->createElement('add');
$subdomain->appendChild($add);
$parent = $xmldoc->createElement('parent', 'siteweb.net');
$add->appendChild($parent);
$name = $xmldoc->createElement('name', $nom);
$add->appendChild($name);
$add->appendChild($xmldoc->createElement('home', '/'.$nom.''));
$property = $xmldoc->createElement('property');
$property->appendChild($xmldoc->createElement('name', 'ssi'));
$property->appendChild($xmldoc->createElement('value', 'true'));
$add->appendChild($property);
return $xmldoc;

}
And the main part :

$host = 'XXX.XXX.XXX.XXX';
$login = 'admin';
$password = 'XXXXXX';

echo "<br/>";
$curl7 = curlInit($host, $login, $password);
$contenu = createSubDomain('Essai')->saveXML();
echo htmlspecialchars($contenu);
$reponse = sendRequest($curl7, $contenu);
echo "<br/>";
echo htmlspecialchars($reponse);
echo "<br/>";
echo "check";

The function curlInit and sendRequest are those used in the examples provided on this site, but I put them here just in case :

/**
* Prepares CURL to perform Plesk API request
* @return resource
*/
function curlInit($host, $login, $password)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://{$host}:8443/enterprise/control/agent.php");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("HTTP_AUTH_LOGIN: {$login}",
"HTTP_AUTH_PASSWD: {$password}",
"HTTP_PRETTY_PRINT: TRUE",
"Content-Type: text/xml")
);

return $curl;
}
/**
* Performs a Plesk API request, returns raw API response text
*
* @return string
* @throws ApiRequestException
*/
function sendRequest($curl, $packet)
{
curl_setopt($curl, CURLOPT_POSTFIELDS, $packet);

$result = curl_exec($curl);

if (curl_errno($curl)) {
$errmsg = curl_error($curl);
$errcode = curl_errno($curl);
curl_close($curl);
throw new ApiRequestException($errmsg, $errcode);
}
curl_close($curl);
return $result;
}

Can anyone please tell me why it doesn't send anything back ? When I modify the property line in the request, the script displays something, but it also fails at creating the subdomain (because the parameters are incorrect).
I am new at this, so it is probably something fairly obvious.
Thanks in advance.
 
I dont think plesk will allow external script.It requires plesk permssion to create the subdomain.
 
Hi ! Did you finally found a solution? I have the same problem you got, so if you're able to help me a bit !

Thanks!
 
Back
Top