Host PHP on IIS

Khimananda Oli 7 min read DevOps
Host PHP on IIS

By Khimananda Oli | Last reviewed: August 2026

To host PHP on IIS reliably, you must configure the FastCGI module rather than legacy CGI or ISAPI handlers. This integration allows Internet Information Services to process PHP requests efficiently while maintaining native Windows authentication and security features. Many administrators struggle with this setup because they rely on outdated tutorials; however, the current standard involves using the Web Platform Installer or manual binary mapping with specific application pool isolation settings.

Client RequestIIS Web ServerHTTP.sys / WASFastCGI ModuleApp Pool (No CLR)PHP-CGI.exe(Non-Thread Safe)File SystemNTFS ACLs
High-level architecture for hosting PHP on IIS: HTTP.sys routes traffic through the FastCGI module to isolated PHP-CGI processes.

How do you install PHP on IIS using the Web Platform Installer?

The most reliable method to host PHP on IIS in 2026 remains the Microsoft Web Platform Installer (Web PI) or its modern command-line equivalents. While some engineers prefer manual zip extraction, Web PI automatically configures the necessary handler mappings, FastCGI settings, and dependency chains that are easy to miss during manual setup. If you are managing multiple servers or need audit-ready compliance for standards like ISO 27001, automated installation ensures consistency across your fleet.

Prerequisites and Feature Enablement

Before installing PHP, you must enable the underlying CGI infrastructure within Windows Server. Without this, IIS cannot spawn external processes regardless of your PHP configuration. Open PowerShell as Administrator and run the following command to install the required roles:

Install-WindowsFeature Web-Server, Web-CGI, Web-Mgmt-Console -IncludeManagementTools

This command installs the core web server, the CGI/FastCGI gateway, and the management console. For teams familiar with Linux stacks, note that this is analogous to installing PHP on Ubuntu but requires explicit feature activation rather than package installation alone. After enabling these features, restart the W3SVC service to apply changes without a full reboot:

Restart-Service W3SVC

Installing PHP via Command Line

For repeatable infrastructure-as-code deployments, avoid the GUI. Use the Web PI command line or download the latest Non-Thread Safe (NTS) PHP binaries directly from windows.php.net. The NTS version is mandatory for IIS because FastCGI handles threading at the web server level; using Thread Safe builds introduces unnecessary overhead and potential stability issues.

  • Download the latest PHP 8.x NTS x64 ZIP package.
  • Extract to C:\PHP (avoid paths with spaces).
  • Rename php.ini-production to php.ini.
  • Enable required extensions by uncommenting lines like extension=curl, extension=mbstring, and extension=openssl.
  • Set cgi.fix_pathinfo=0 to prevent path traversal vulnerabilities.

How do you configure FastCGI settings for optimal performance?

Once PHP is installed, you must register it with IIS as a FastCGI application. This step tells IIS how to spawn and manage PHP worker processes. A common mistake is leaving default instance limits, which causes request queuing under load. In production environments serving Nepali e-commerce sites or enterprise applications, tuning these values based on available RAM is critical for maintaining low latency.

Registering the Handler Mapping

You can configure handler mappings via the IIS Manager GUI or, preferably, through appcmd for documentation and automation purposes. The following command registers PHP 8.x globally:

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /+"[name='PHP_via_FastCGI',path='*.php',verb='GET,HEAD,POST',modules='FastCgiModule',scriptProcessor='C:\PHP\php-cgi.exe',resourceType='Either']"

After registering the handler, configure the FastCGI application settings to control process recycling and concurrency. These settings directly impact throughput and memory usage:

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCgi /+"[fullPath='C:\PHP\php-cgi.exe',maxInstances='8',instanceMaxRequests='10000',activityTimeout='300',requestTimeout='300']"
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCgi /+"[fullPath='C:\PHP\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']"

The maxInstances value should typically match your CPU core count or slightly exceed it for I/O-bound workloads. Setting instanceMaxRequests and PHP_FCGI_MAX_REQUESTS to matching values prevents race conditions during process recycling. For deeper insights into monitoring these metrics once configured, refer to our guide on Prometheus metrics monitoring fundamentals adapted for Windows exporters.

Incoming HTTP RequestFastCGI Process ManagerChecks Instance PoolPHP Worker ProcessesInstance 1Instance 2Instance NRecycling...Response ReturnedProcess Reused or KilledMax Requests = 10,000 | Activity Timeout = 300s
FastCGI lifecycle: requests are distributed across persistent PHP workers that recycle after reaching maxInstances limits.

How do you secure PHP applications on Windows Server?

Security when you host PHP on IIS requires a defense-in-depth approach distinct from Linux environments. NTFS permissions replace POSIX chmod, and Windows Authentication integrates directly with Active Directory. Neglecting these specifics leaves applications vulnerable to privilege escalation and data leakage. Always assume the application will be probed for vulnerabilities and configure accordingly.

Application Pool Isolation

Never run PHP sites in the DefaultAppPool. Create a dedicated application pool for each site or tenant with the following critical settings:

  • .NET CLR Version: Set to "No Managed Code". PHP does not use the CLR; loading it wastes memory and increases attack surface.
  • Identity: Use ApplicationPoolIdentity or a specific service account with minimal privileges. Never use LocalSystem or Administrator.
  • Load User Profile: Set to True if your application relies on user-specific environment variables or certificate stores.

File System Permissions

Grant the application pool identity (IIS AppPool\YourPoolName) only the access it needs. For a typical Laravel or WordPress deployment:

DirectoryPermissionRationale
Web Root (public)Read & ExecuteServes static assets and index.php
Storage / LogsModifyRequired for caching, sessions, logging
Config FilesRead OnlyPrevents malicious modification of .env
Uploads DirectoryModify (Restricted)Isolate uploads; disable script execution

To disable script execution in upload directories, add a local web.config file within that folder containing a handler removal directive. This prevents attackers from executing uploaded PHP shells even if they bypass validation logic.

What are the key differences between IIS and Nginx for PHP hosting?

Engineers often debate whether to host PHP on IIS or migrate to Linux-based alternatives. Understanding the trade-offs helps make informed architectural decisions, especially for organizations with existing Windows investments or compliance requirements mandating Windows Server.

CriteriaIIS + FastCGINginx + PHP-FPM
IntegrationNative Windows Auth, AD, KerberosRequires additional modules/config
PerformanceExcellent for ASP.NET/PHP mixed loadsSuperior raw throughput for pure PHP
ManagementGUI + PowerShell + appcmdText config + systemd
LicensingWindows Server license requiredOpen source / free
EcosystemAzure DevOps, SQL Server, ExchangeDocker, Kubernetes, Cloud Native

If your organization already operates Windows Server for Active Directory or SQL Server, hosting PHP on IIS reduces operational friction. However, for greenfield microservices or containerized workloads, consider exploring Docker for beginners to evaluate portable alternatives before committing to platform-specific configurations.

IIS + FastCGI✓ Native Windows Authentication✓ Integrated Management Tools✓ Azure & SQL Server Synergy⚠ Higher Licensing Cost⚠ Smaller Community EcosystemNginx + PHP-FPM✓ Superior Raw Throughput✓ Container-Native Architecture✓ Zero Licensing Fees⚠ Complex Windows Integration⚠ Steeper Learning Curve
Decision matrix comparing IIS versus Nginx for PHP hosting across cost, integration, and performance dimensions.

Deploy PHP on IIS with Confidence

Successfully configuring PHP on IIS requires attention to FastCGI tuning, strict NTFS permissions, and proper application pool isolation. When implemented correctly, this stack delivers enterprise-grade reliability with seamless Windows ecosystem integration. Start by validating your handler mappings and testing with phpinfo(), then progressively harden security and optimize performance based on real traffic patterns. If you need assistance auditing your Windows Server PHP deployment or migrating legacy applications to modern IIS configurations, reach out for a consultation tailored to your infrastructure.

Frequently Asked Questions

Use FastCGI via the Web Platform Installer or manual configuration. Never use CGI mode as it spawns a new process per request, causing severe performance degradation under load.

Yes. Configure URL Rewrite rules for routing, enable FastCGI, and ensure file permissions allow the IUSR account to write to storage and bootstrap cache directories.

Yes. PHP is open source and IIS includes FastCGI support natively on Windows Server. You only pay for the Windows Server license and hardware resources.

Run wpeinstall php from an elevated PowerShell prompt using the Web Platform Installer command line tool for silent, dependency-aware setup.

Yes. Download the Non-Thread Safe x64 build from windows.php.net and register it as a FastCGI handler mapping in IIS Manager.

Check if FastCGI is enabled instead of CGI. Verify instanceMaxRequests is set above zero and monitor worker process recycling settings in application pool configuration.

Enable detailed error messages temporarily, check Event Viewer for FastCGI crashes, and verify php.ini paths and extension directory configurations are absolute not relative.

Grant IUSR read access to web roots and modify access to upload, cache, and log directories. Never grant full control to prevent security escalation attacks.

Always use Non-Thread Safe builds with FastCGI. Thread Safe versions add unnecessary overhead since each FastCGI worker runs in its own isolated process space.

Install the URL Rewrite module and import Apache mod_rewrite rules or create custom inbound rules matching your framework routing requirements in web.config files.

Yes. Register separate FastCGI applications pointing to different php-cgi.exe binaries and assign specific handler mappings per site or virtual directory.

Disable dangerous functions like exec and shell_exec in php.ini, restrict open_basedir, hide version headers, and apply Windows Defender exclusions only for active PHP processes.

Enable both IIS W3C logging and PHP error_log directive. Configure log rotation and monitor Event Viewer Application logs for FastCGI process failures and warnings.

Register the new PHP version as a separate FastCGI application, test on a staging site, then swap handler mappings during low-traffic maintenance windows.

Performance is comparable with FastCGI. Choose IIS for Active Directory integration and Windows ecosystem tools; choose Apache or Nginx for broader community support and Linux optimization.