WebAdministrationDsc icon indicating copy to clipboard operation
WebAdministrationDsc copied to clipboard

xIisModule not adding FastCGI handler

Open saikovvuri opened this issue 5 years ago • 4 comments

Details of the scenario you tried and the problem that is occurring

Trying to register the php cgi module with IIS. However the Handler/Module "FastCgiModule" is not registered.

Verbose logs showing the problem

Suggested solution to the issue

Could not xIisModule could not work. Had to run the below command outside of the configuration:

New-WebHandler -Name "PHP-FastCGI" -Path "*.php" -Verb "*" -Modules "FastCgiModule" -ScriptProcessor "c:\php\php-cgi.exe" -ResourceType Either

The DSC configuration that is used to reproduce the issue (as detailed as possible)

configuration PhpOnIis
{
     param
    (
        [Parameter(Mandatory = $true)]
        [string] $PackageFolder,
        [Parameter(Mandatory = $true)]
        [string] $PhpDownloadUri,
        [Parameter(Mandatory = $true)]
        [string] $VcplusRedistDownloadUri,
        [Parameter(Mandatory = $true)]
        [String] $PhpInstallPath,
        [Parameter(Mandatory = $true)]
        [string] $phpIniConfigurationPath
        
    )

    Import-DscResource -ModuleName xPSDesiredStateConfiguration
    Import-DscResource -ModuleName xWebAdministration
    

    $features = @("Web-Server",
	"Web-Mgmt-Tools",
	"web-Default-Doc",
	"Web-Dir-Browsing",
	"Web-Http-Errors",
	"Web-Static-Content",
	"Web-Http-Logging",
	"web-Stat-Compression",
	"web-Filtering",
	"web-CGI",
	"web-ISAPI-Ext",
	"web-ISAPI-Filter"
    )

    $dependsOn = @()

    $features | ForEach-Object -Process {
	    WindowsFeature $_ {
		    Name   = $_
		    Ensure = "Present" 
	    }
	    $dependsOn += "[WindowsFeature]$($_)"
    }

     @(
	    ".NET v2.0" ,
	    ".NET v2.0 Classic",
	    ".NET v4.5",
	    ".NET v4.5 Classic",
	    "Classic .NET AppPool",
	    "DefaultAppPool"
    ) | ForEach-Object -Process {
	    xWebAppPool "Remove-$($_.ToString().Replace(" ","").Replace(".",""))"
	    {
		    Name      = $_
		    Ensure    = "Absent"
		    DependsOn = $dependsOn
	    }
    }

    xWebSite RemoveDefaultWebSite
    {
	    Name         = "Default Web Site"
	    PhysicalPath = "C:\inetpub\wwwroot"
	    Ensure       = "Absent"
        DependsOn    = $dependsOn
    }

    # Download and install Visual C ++ from chocolatey.org
    Package vcRedist
    {
        Path = $VcplusRedistDownloadUri
        ProductId = "EEA66967-97E2-4561-A999-5C22E3CDE428"
        Name = "Microsoft Visual C++ 2015-2019"
        Arguments = "/install /passive /norestart"
    }

    xScript EnableTLS12
    {
        SetScript = {
        [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol.toString() + ', ' + [Net.SecurityProtocolType]::Tls12
        }
        TestScript = {
            return ([Net.ServicePointManager]::SecurityProtocol -match 'Tls12')
        }
        GetScript = {
            return @{
            Result = ([Net.ServicePointManager]::SecurityProtocol -match 'Tls12')
            }
        }
    }

    $phpZip = Join-Path $PackageFolder "php.zip"

    # Make sure the PHP archine is in the package folder
    xRemoteFile phpArchive
    {
        uri = $PhpDownloadUri
        DestinationPath = $phpZip
        DependsOn = @("[xScript]EnableTLS12")
    }

    # Make sure the content of the PHP archive are in the PHP path
    Archive php
    {
        Path = $phpZip
        Destination  = $PhpInstallPath       
    }

    # Make sure the php.ini is renamed in the Php folder
    File PhpIni
    {
        SourcePath = "$($PhpInstallPath)\php.ini-development"
        DestinationPath = "$($PhpInstallPath)\php.ini"
        DependsOn = @("[Archive]PHP")
        MatchSource = $true
    }



     # Make sure the php cgi module is registered with IIS
    xIisModule phpHandler
    {
        Name = "phpFastCgi"
        Path = "$($PhpInstallPath)\php-cgi.exe"
        RequestPath = "*.php"
        Verb = "*"
        Ensure = "Present"
        ModuleType = "FastCgiModule"
        DependsOn = @("[Package]vcRedist","[File]PhpIni")
        
    }

    # Make sure the php binary folder is in the path
    Environment PathPhp
    {
        Name = "Path"
        Value = ";$($PhpInstallPath)"
        Ensure = "Present"
        Path = $true
        DependsOn = "[Archive]PHP"
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2016 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 14393.3564.amd64fre.rs1_release.200303-1942
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value                                                                                                                                     
----                           -----                                                                                                                                     
PSVersion                      5.1.14393.3471                                                                                                                            
PSEdition                      Desktop                                                                                                                                   
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                   
BuildVersion                   10.0.14393.3471                                                                                                                           
CLRVersion                     4.0.30319.42000                                                                                                                           
WSManStackVersion              3.0                                                                                                                                       
PSRemotingProtocolVersion      2.3                                                                                                                                       
SerializationVersion           1.1.0.1             

Version of the DSC module that was used

saikovvuri avatar Mar 28 '20 21:03 saikovvuri

@saikovvuri did you get any error when running this configuration that could help?

johlju avatar Mar 31 '20 18:03 johlju

The issue is this command:

        Add-webconfiguration /system.webServer/handlers iis:\ -Value @{
            Name = $Name
            Path = $RequestPath
            Verb = $Verb -join ','
            Module = $ModuleType
            ScriptProcessor = $Path
        }

'Module' should be 'Modules'

DCMattyG avatar May 04 '20 08:05 DCMattyG

This is the same issue as https://github.com/dsccommunity/xWebAdministration/issues/305 maybe it should be merged?

jrdbarnes avatar Nov 09 '20 18:11 jrdbarnes