How to Upgrade PHP on IIS With FastCGI on Windows Server
In this article11 sections
PHP runs well on Windows Server with IIS, through a component called FastCGI. IIS starts PHP processes on demand, passes them requests, and collects the answers. Upgrading PHP on a server you manage yourself means installing the new version into its own folder, pointing IIS at it, and checking that the settings and extensions came across. Nothing is installed by a package manager, so the details that Linux hides are yours to handle: the right build, the runtime it needs, the php.ini file, the folder permissions and the handler mapping. This guide goes through each one, with a rollback that is only a path change.
It is written for Windows servers you administer. On managed Windows hosting with Plesk, such as SiteHarbour’s Windows hosting plans, switch the version in the control panel instead, as described in how to upgrade PHP on Plesk, because Plesk manages the mappings and will overwrite manual changes.
Choose the right build
PHP for Windows comes from the official Windows download page, in several variants. For IIS with FastCGI, you want the Non Thread Safe (NTS) build, for x64. FastCGI runs each PHP process separately, so thread safety is not needed, and the NTS build is faster. The Thread Safe build is for running PHP as an Apache module on Windows, which is not this case.
Each build needs a matching Microsoft Visual C++ Redistributable runtime. The download page names the one required, such as the Visual C++ 2015-2022 x64 package. Install it before you start, or PHP fails to launch with a missing DLL error.
Before you start
- Snapshot the server or take a backup, and export the site configuration.
- Record the current state. In a command prompt:
C:\PHP\8.3\php.exe -v
C:\PHP\8.3\php.exe -m > C:\PHP\modules-before.txt
copy C:\PHP\8.3\php.ini C:\PHP\php-8.3.ini.backup
Expected: the version, a saved list of loaded extensions, and a copy of the settings. Adjust the folder to the one you use now. Check your own code for compatibility first, as in how to check your code for PHP compatibility before you upgrade.
Step 1: Install the new version in its own folder
Download the NTS x64 zip file for the version you want, and check its published checksum against the one on the download page. Extract it into a new folder named for the version, such as C:\PHP\8.4. Never extract over the old folder, because then you lose the rollback.
Copy the production template to the live settings file:
copy C:\PHP\8.4\php.ini-production C:\PHP\8.4\php.ini
Check that it runs on its own, before IIS is involved:
C:\PHP\8.4\php.exe -v
Expected: the new version line. A pop-up about a missing DLL means the Visual C++ runtime is missing or the wrong one.
Step 2: Set up php.ini
Open C:\PHP\8.4\php.ini in a text editor that does not change the line endings. Set the values that Windows needs and the ones you carried from the old file:
extension_dir = "C:\PHP\8.4\ext"
cgi.force_redirect = 0
cgi.fix_pathinfo = 1
fastcgi.impersonate = 1
date.timezone = "UTC"
memory_limit = 256M
upload_max_filesize = 32M
post_max_size = 32M
max_execution_time = 60
Then enable the extensions. Remove the leading semicolon from each line you need, such as extension=curl, extension=mbstring, extension=openssl, extension=pdo_mysql, extension=mysqli, extension=gd, extension=intl, extension=zip and extension=fileinfo. If you use Microsoft SQL, the SQL Server drivers are a separate download from Microsoft, and the file names carry the PHP version. Compare against modules-before.txt, so nothing from the old setup is lost. OPcache is built in, and you turn it on with zend_extension=opcache and opcache.enable=1.
Test the settings from the command line:
C:\PHP\8.4\php.exe -m
Expected: the list of enabled extensions, with no warnings printed above it. A warning such as Unable to load dynamic library names the file that is wrong or missing.
Step 3: Grant the folder permissions
IIS runs PHP under the application pool identity, which belongs to the IIS_IUSRS group. Give that group read and execute permission on the PHP folder, and nothing more:
icacls "C:\PHP\8.4" /grant "IIS_IUSRS:(OI)(CI)RX"
If PHP writes sessions or uploads to temporary folders, give the same group modify rights on those folders only. A common error after an upgrade is a session folder that the new process cannot write to, which logs users out on every request.
Step 4: Point IIS at the new PHP
Open IIS Manager, select the server or the site, and open Handler Mappings. Edit the PHP mapping, usually named PHP_via_FastCGI, and change the executable to C:\PHP\8.4\php-cgi.exe. Confirm the prompt that offers to create the FastCGI application. Then open FastCGI Settings at the server level, and check that the new php-cgi.exe entry exists and has the environment variable PHPRC set to the PHP folder, so it finds the right php.ini.
The same mapping in a site’s web.config looks like this, and it lets you move one site at a time:
<handlers>
<add name="PHP_via_FastCGI" path="*.php" verb="*" modules="FastCgiModule"
scriptProcessor="C:\PHP\8.4\php-cgi.exe" resourceType="Either" />
</handlers>
A handler can be defined in web.config only when the server allows it. On a server where handlers are locked, change the mapping at the server level in IIS Manager. Keep a copy of web.config before you edit it, because an error in the file stops the site, as covered in how to fix ASP.NET Core 500.19 configuration error on IIS.
Step 5: Recycle and test
Recycle the application pool, or run iisreset if you changed server-level settings and can accept a short interruption:
iisreset
Create a temporary file in the site folder named version-check.php that contains <?php echo PHP_VERSION;. Open it in a browser, then delete it. Expected: the new version. Test the pages that matter: the home page, the login, a form and anything that uses the database. Check the Windows event log and the PHP error log, whose path is set by error_log in php.ini.
Step 6: Update scheduled tasks and keep the old folder
Windows scheduled tasks that call php.exe by full path keep using the old version. Open Task Scheduler and change each one. Add the new folder to the system PATH if command-line tools need it. Keep the old C:\PHP\8.3 folder for at least a week, as your rollback.
Rollback
Change the handler mapping back to the old php-cgi.exe, and recycle the pool. Because the old folder is untouched, the site is back to the previous state at once. Restore the database only if the new version triggered a data change.
Common mistakes
- Using the Thread Safe build. For FastCGI, use Non Thread Safe.
- Missing the Visual C++ runtime. PHP does not start without it.
- Extracting over the old folder. You lose the rollback.
- Wrong
extension_dir. No extension loads, and every database call fails. - Forgetting
PHPRC. PHP reads a differentphp.inithan you edited. - Not giving
IIS_IUSRSaccess. The pool cannot run or write what it needs.
Frequently asked questions
Can I run two PHP versions on one IIS server?
Yes. Each site can have its own handler mapping that names a different php-cgi.exe, so you can move sites one at a time.
Do I need the Web Platform Installer?
No. It is no longer the usual route. Manual installation from the zip file gives you control of the version and the folder.
Why do I get a 500 error after the change?
Usually the handler path, a missing DLL or a php.ini value that the new version rejects. The PHP and IIS logs name which.
Is PHP on IIS as fast as on Linux?
It can be close for typical sites with OPcache enabled. Disk and database configuration usually matter more than the platform.
On a self-managed Windows server, upgrading PHP is a new folder, the right NTS build with its runtime, a configured php.ini, correct folder permissions and a handler mapping that points at the new php-cgi.exe. Verify the version with a temporary file, update scheduled tasks, and keep the old folder as the rollback for a week. For the broader platform choice, read Windows hosting or Linux hosting: which to choose.
Want this done for you? If you would rather have an engineer plan and carry out the work on your own site, you can hire the author through the Upwork profile of Munaf Sheikh.