How to install PHP on IIS: FastCGI, php.ini and several PHP versions per site
Install PHP on IIS 10 with FastCGI on Windows Server 2019, 2022 or 2025, configure php.ini for IIS, run different PHP versions on different sites, and replace .htaccess with URL Rewrite.

Key takeaways
- Use the Non Thread Safe (NTS) x64 build of PHP with IIS FastCGI, plus the matching Visual C++ runtime.
- Each PHP version is one FastCGI application; a site picks its version through its *.php handler mapping.
- Per-site php.ini works by giving the FastCGI application a "-c" argument or a PHPRC variable.
- IIS ignores .htaccess; rewrite rules go into web.config through the URL Rewrite module.
To install PHP on IIS, turn on the IIS CGI role service (it includes FastCGI), unzip the Non Thread Safe x64 build of PHP into a folder such as C:\PHP\8.4, register php-cgi.exe as a FastCGI application, and map *.php to it. After that, every site can use that PHP version, and you can register more versions side by side and pick one per site. This guide shows each step with PowerShell and appcmd, for IIS 10 on Windows Server 2019, 2022 and 2025.
If you also run ASP.NET on the same server, read hosting ASP.NET and PHP side by side for the bigger picture. This post goes deeper on PHP itself.
Step 1: turn on IIS and FastCGI
Install-WindowsFeature Web-Server, Web-CGI, Web-Mgmt-Console
Web-CGI installs both CGI and the FastCGI module. You do not need any other role service for PHP.
Step 2: download the right PHP build
On windows.php.net, take the VS17 x64 Non Thread Safe zip of the version you want. Non Thread Safe (NTS) is correct for FastCGI: each php-cgi.exe process handles one request at a time, so thread safety only costs speed.
PHP for Windows needs the Microsoft Visual C++ Redistributable (the 2015–2022 x64 package). Install it first, or php-cgi.exe will not start and IIS returns a 500 error with no useful detail.
Unzip into a versioned folder and check it runs:
Expand-Archive .\php-8.4.x-nts-Win32-vs17-x64.zip -DestinationPath C:\PHP\8.4
C:\PHP\8.4\php-cgi.exe -v
The versioned folder name matters later, when a second version sits next to it.
Step 3: create php.ini for IIS
Copy php.ini-production to php.ini in the same folder and change these lines:
extension_dir = "ext"
fastcgi.impersonate = 1
cgi.fix_pathinfo = 1
cgi.force_redirect = 0
date.timezone = "UTC"
error_log = "C:\PHP\logs\php-8.4-errors.log"
display_errors = Off
log_errors = On
extension=curl
extension=mbstring
extension=openssl
extension=pdo_mysql
extension=mysqli
extension=fileinfo
extension=intl
fastcgi.impersonate = 1 lets PHP run file operations as the identity IIS authenticated, which for anonymous requests is the application pool account when the site is set up as described in IIS application pool identity explained. Give that account write access to the error log folder, or PHP cannot write the log.
Step 4: register PHP with FastCGI
Register the FastCGI application at the server level, and keep PHP's own request limit and IIS's in step:
$appcmd = "$env:windir\system32\inetsrv\appcmd.exe"
$php = 'C:\PHP\8.4\php-cgi.exe'
& $appcmd set config /section:system.webServer/fastCgi "/+[fullPath='$php']" /commit:apphost
& $appcmd set config /section:system.webServer/fastCgi "/[fullPath='$php'].instanceMaxRequests:10000" /commit:apphost
& $appcmd set config /section:system.webServer/fastCgi "/+[fullPath='$php'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']" /commit:apphost
If PHP_FCGI_MAX_REQUESTS is lower than instanceMaxRequests, PHP exits while IIS still expects it to serve requests, and some requests fail.
Other FastCGI attributes worth sizing to the server: maxInstances (how many PHP processes per application), activityTimeout and requestTimeout (raise them for long imports), and idleTimeout.
Step 5: map .php to PHP for a site
& $appcmd set config 'example.com' /section:system.webServer/handlers `
"/+[name='PHP84_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='$php',resourceType='Either']"
& $appcmd set config 'example.com' /section:system.webServer/defaultDocument "/+files.[value='index.php']"
Test with a file that prints the version, then delete it:
Set-Content C:\sites\example.com\v.php '<?php echo PHP_VERSION;'
If you set the handler at the server level instead (no site name), every site gets that PHP version by default.
Running several PHP versions per site
Each PHP version is a separate FastCGI application. Repeat steps 2 to 4 for, say, C:\PHP\8.3\php-cgi.exe. Then give each site the handler for its version: site A maps *.php to C:\PHP\8.3\php-cgi.exe, site B to C:\PHP\8.4\php-cgi.exe. If you mapped a default at the server level, remove the inherited handler on the site first, or put the site's handler ahead of it, so the right one matches.
For per-site php.ini files with the same PHP build, register the same php-cgi.exe again with a -c argument. IIS identifies a FastCGI application by its path and its arguments together, and the handler's scriptProcessor uses the form path|arguments:
$phpArgs = '-c C:\sites\example.com\php\php.ini'
& $appcmd set config /section:system.webServer/fastCgi "/+[fullPath='$php',arguments='$phpArgs']" /commit:apphost
& $appcmd set config 'example.com' /section:system.webServer/handlers `
"/[name='PHP84_FastCGI'].scriptProcessor:$php|$phpArgs"
This also gives each site its own pool of PHP processes, which helps isolation. For small per-directory changes, PHP's CGI/FastCGI mode also reads .user.ini files (see user_ini.filename in php.ini).
URL Rewrite instead of .htaccess
IIS does not read .htaccess. Install the URL Rewrite module from Microsoft (it is a separate download, not a Windows feature), then put rules in the site's web.config. A front-controller rule, the IIS version of the usual RewriteRule ^ index.php:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Front controller" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
IIS Manager can import many .htaccess rules (URL Rewrite → Import Rules). Review what it produces; not every Apache directive has an equivalent.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
404.3 on .php files |
No handler mapping for *.php on the site |
Add the handler (step 5) |
| 500 with "FastCGI process exited unexpectedly" | Missing Visual C++ runtime or a broken extension line | Run php-cgi.exe -v on the console and read the error |
| 500.19 after adding rewrite rules | URL Rewrite not installed, or invalid XML | Install URL Rewrite; check the file |
| Uploads fail | No write access, or upload_max_filesize/post_max_size too low |
Grant Modify on the upload folder only; raise the limits |
| Slow first request after a quiet period | Idle PHP processes ended | Raise idleTimeout, or keep the pool warm |
More 500 causes are in IIS 500 internal server error troubleshooting.
FAQ
Thread Safe or Non Thread Safe PHP for IIS?
Non Thread Safe. FastCGI runs one request per process, so the thread-safe build only adds overhead.
Can two sites use different PHP versions on the same IIS server?
Yes. Register each version as its own FastCGI application and map *.php per site to the version it needs.
Where does IIS look for php.ini?
PHP looks in the folder of php-cgi.exe unless you pass -c or set PHPRC. Run php-cgi.exe --ini to check.
Does IIS support .htaccess?
No. Use URL Rewrite rules in web.config, and .user.ini for PHP settings.
In Zopanel for Windows
Zopanel installs PHP 8.3 and 8.4 from its signed runtime catalog (it checks the SHA-256 and the publisher's signature), and each site picks its version in the Runtime tab. The panel writes the handler and the site's php.ini, lets the site owner change an allow-list of directives and extensions capped by the plan, and sizes FastCGI limits from the server's capacity (the sizing is limited; see known issues). PHP 8.5 is in the catalog but not yet tested on Windows, and PHP 7.x is not offered. See PHP on Zopanel and the apps feature page. Start on the Free plan (1 server, 10 sites): download, or compare pricing.
Put your Windows servers on Zopanel
Start free with 1 server and 10 websites on Windows Server 2022 or 2025, or talk to us about moving from Plesk and about licenses for several servers.
Free for 1 server, 10 websites · No credit card · Signed MSI
Keep reading

Hosting ASP.NET and PHP side by side on IIS
A practical guide to running PHP, ASP.NET 4.x, ASP.NET Core and Classic ASP sites on one Windows Server with IIS, and what a panel should handle for you.

WordPress on IIS and Windows Server: a complete setup guide
Install WordPress on IIS on Windows Server 2019, 2022 or 2025: PHP through FastCGI, a MySQL or MariaDB database, pretty permalinks with web.config, and file permissions that let WordPress upload without opening the whole site.

Free SSL certificate on IIS with Let's Encrypt: ACME, SNI bindings and renewal
How to get a free Let's Encrypt SSL certificate for IIS on Windows Server: how ACME validation works, how to bind certificates with SNI for many sites on one IP, how renewal must be automated, and how win-acme and Zopanel each handle it.