'Create Website in IIS using commands in core php [closed]

Want to create website in my IIS with cmd commands using php. I have found various command in cmd but how to handle that in php

Commands:

  1. #cd c:\Windows\System32\inetsrv (that goes to folder)
  2. #appcmd add site /name:windows.testing.net /bindings:http://*:80 /physicalpath:”C:\sites\windows.testing.net” (that creates the website in IIS)

This get's the work done from cmd. How to do that programmatically please help Thanks

// i changed my around something like this it doesn't executes nor shows any error
<?php 
$webUrl         = "TestSite";
$physical_Path  = "path";
$psPath         = "powershell.exe";
$psDIR          = "C:\Windows\System32\WindowsPowerShell\v1.0\\"; 
$psScript       = 'New-IISSite -Name "'.$webUrl.'" -BindingInformation "*:80:'.$webUrl.'" -PhysicalPath "'.$physical_Path.'"';
$runScript      = $psDIR. $psScript;
$runCMD         = $psPath." ".$runScript;
//echo $runCMD;exit;
$output         = shell_exec($runCMD);
echo('<pre>');echo($output); echo('</pre>');
?>


Solution 1:[1]

I got it done by using following php exec() on local server.

<?php 
$output         = null;
$retval         = null;
$successMsg     = "";
$errorMsg       = "";
exec(powershell.exe -executionpolicy bypass -NoProfile -Command New-IISSite -Name "www.test.com" -BindingInformation "*:80:www.test.com" -PhysicalPath "C:\xampp\htdocs" 2>&1);
if(empty($output)){
    $successMsg     = "Done";
}else{
    $errorMsg       = $output[0];
}
?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 self_divident