
&"$PSScriptRoot/../Scripts/vars.ps1"
&"$PSScriptRoot/../Scripts/fn-iis.ps1"

## TODO Create Application Pool

$site = (Split-Path "$ROOT" -Leaf)
$hasSite = (&"$IISexe" list site "$site")
if (-Not($hasSite)) {
    Write-Host "Creating IIS Site '$site' for '$ROOT'"
    &"$IISexe" add site /name:"$site" /bindings:http/*:80: /physicalPath:"$ROOT\Web"
    ## TODO Assign Application Pool
}

&"$IISexe" set config /section:system.webServer/handlers "/-[name='StaticFile']"
&"$IISexe" set config /section:system.webServer/handlers "/+[name='StaticFile',path='*',verb='GET',modules='StaticFileModule',resourceType='File',requireAccess='Read']"
&"$IISexe" set config /section:system.webServer/handlers "/+[name='PHP$PHP_VERSION',path='*.php',verb='GET,POST,HEAD',modules='FastCgiModule',scriptProcessor='C:\Program Files\PHP\v$PHP_VERSION\php-cgi.exe',resourceType='File',requireAccess='Script']"
&"$IISexe" set config /section:system.webServer/handlers /accessPolicy:Read,Script /commit:apphost

&"$IISexe" set config -section:system.webServer/fastCGI "/+[fullPath='C:\Program Files\PHP\v$PHP_VERSION\php-cgi.exe',InstanceMaxRequests='10000',stderrMode='ReturnGeneric500',activityTimeout='180']"
