Euan's Blog

Setting up PHP with FastCGI on Windows using Apache

I've recently been updating a few Windows machines to PHP 8.2, and decided that as I was doing the update I'd move from mod_php to using FastCGI instead.

On a Linux server I would tend to use PHP-FPM, which unfortunately isn't available for Windows. Instead, I ended up opting for mod_fcgid.

The Apache Haus distribution doesn't ship with mod_fcgid included by default though, and you have to install it as an extra step which I thought was worth documenting for future reference.

Install PHP

I use Chocolatey to manage packages, so installing PHP is as easy as:

choco install php

The manual installation process is pretty simple too though:

Copy the php.ini-development or php.ini-production file to php.ini and make any required changes.

Check that PHP is working by checking its version:

php -v

You should expect some output such as:

PHP 8.2.0 (cli) (built: Dec  6 2022 15:25:41) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.0, Copyright (c) Zend Technologies

Install Apache

Again, using Chocolatey this step is easy:

choco install apache-httpd --params '/port:80 /installLocation:C:\Apache24'

This will install Apache as a service and will install to the directory C:\Apache24.

Manual installation is similarly easy:

Make any required changes to C:\Apache24\Apache24\conf\httpd.conf to configure the server, such as setting the document root, enabling modules, etc.

Check the syntax of the server configuration file:

httpd -t

You should expect some output such as:

Syntax OK

Install mod_fcgid

We have to install mod_fcgid manually, as it is not included when installed either through Chocolatey or manually.

Now that we have the module installed, we need to load and configure it:

Closing Thoughts

Immediately after switching to mod_fcgid, there was a perceivable performance improvement. This is most likely due to mod_php requiring a thread safe version of PHP which will include locks.

The actual upgrade to PHP 8.2 from 8.1 itself also went pretty smoothly, with no breakage to existing code - which is always nice!