Created
September 29, 2025 03:04
-
-
Save jcefoli/0650a91d863937ef6f8caa494502b426 to your computer and use it in GitHub Desktop.
Configure PHP on IIS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Requires -RunAsAdministrator | |
| <# Ported to powershell from https://www.php.net/manual/en/install.windows.iis.php #> | |
| # PHP Installation Path. CHANGEME | |
| $phpPath = 'C:\frameworks\php' | |
| # Check for file $phpPath\php-cgi.exe else exit 1 | |
| if (!(Test-Path "$phpPath\php-cgi.exe")) { | |
| Write-Error "PHP executable not found at $phpPath\php-cgi.exe" | |
| exit 1 | |
| } | |
| # Clear current PHP handlers | |
| . $env:windir\system32\inetsrv\appcmd clear config /section:system.webServer/fastCGI | |
| # Remove PHP handler if it exists | |
| $handler = & $env:windir\system32\inetsrv\appcmd list config /section:system.webServer/handlers | Select-String 'name="PHP_via_FastCGI"' | |
| if ($handler) { | |
| & $env:windir\system32\inetsrv\appcmd set config /section:system.webServer/handlers "/-[name='PHP_via_FastCGI']" | |
| } | |
| # Set up the PHP handler | |
| . $env:windir\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI /+["fullPath='$phpPath\php-cgi.exe'"] | |
| . $env:windir\system32\inetsrv\appcmd set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='$phpPath\php-cgi.exe',resourceType='Unspecified'] | |
| . $env:windir\system32\inetsrv\appcmd set config /section:system.webServer/handlers /accessPolicy:Read,Script | |
| # Configure FastCGI Variables | |
| & $env:windir\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi "/[fullPath='$phpPath\php-cgi.exe'].instanceMaxRequests:10000" | |
| & $env:windir\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi "/+[fullPath='$phpPath\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']" | |
| & $env:windir\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi "/+[fullPath='$phpPath\php-cgi.exe'].environmentVariables.[name='PHPRC',value='$phpPath\php.ini']" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment