Improve PHP performance with FastCGI on XAMPP for Windows

I have been using XAMPP on Windows for development for many years and found it to work quite well. Unfortunately performance is not that great.

By default XAMPP uses Mod-PHP to execute PHP within the Apache process. Changing this to use FastCGI improves performance by creating separate Windows tasks to run the PHP processes.

My XAMPP is installed into C:\Apps\xampp\ – adjust for your own environment.

First determine if you are running 32-bit or 64-bit XAMPP using phpinfo() by checking the Architecture (x86 is 32-bit, x64 is 64-bit).

Note the Server API is Apache 2.0 Handler – this is what we are replacing.

Download the latest version of mod_fcgid from Apache Lounge (https://www.apachelounge.com/download/). You will need either mod_fcgid-x.x.x-win32-VCxx.zip or mod_fcgid-x.x.x-win64-VCxx.zip depending on your Architecture.

Copy the mod_fcgid.so file from the ZIP archive to the XAMPP apache\modules directory. In my XAMPP installation this was C:\Apps\xampp\apache\modules.

Stop Apache in the XAMPP Control Panel and edit the Apache configuration file C:\Apps\xampp\apache\conf\extra\httpd-xampp.conf to change the PHP-Module setup to use FastCGI.

#
# PHP-Module setup
#
LoadFile "C:/Apps/xampp/php/php7ts.dll"
LoadFile "C:/Apps/xampp/php/libpq.dll"
LoadModule php7_module "C:/Apps/xampp/php/php7apache2_4.dll"

<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

Change this section to:

#
# PHP-Module setup
#
LoadFile "C:/Apps/xampp/php/php7ts.dll"
LoadFile "C:/Apps/xampp/php/libpq.dll"

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule fcgid_module>
	FcgidInitialEnv PATH "C:/Apps/xampp/php"
	FcgidInitialEnv SystemRoot "C:/Windows"
	FcgidInitialEnv SystemDrive "C:"
	FcgidInitialEnv TEMP "C:/Apps/xampp/tmp"
	FcgidInitialEnv TMP "C:/Apps/xampp/tmp"
	FcgidInitialEnv windir "C:/windows"
	FcgidIOTimeout 64
	FcgidConnectTimeout 16
	FcgidMaxRequestsPerProcess 1000 
	FcgidMaxProcesses 3
	FcgidMaxRequestLen 8131072
	# Location php.ini:
	FcgidInitialEnv PHPRC "C:/Apps/xampp/php"
	FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

	<Files ~ "\.php$">
		Options Indexes FollowSymLinks ExecCGI 
		AddHandler fcgid-script .php
		FcgidWrapper "C:/Apps/xampp/php/php-cgi.exe" .php
	</Files>
</IfModule>

Change the phpMyAdmin section to enable FastCGI to avoid forbidden exceptions:

    Alias /phpmyadmin "C:/Apps/xampp/phpMyAdmin/"
    <Directory "C:/Apps/xampp/phpMyAdmin">

        # add this option allow FastCGI
        Options ExecCGI

        AllowOverride AuthConfig
        Require local
        ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
    </Directory>

Start Apache in the XAMPP Control Panel and check phpinfo() to check that FastCGI is enabled.

Something to note is that when stopping the Apache process, the XAMPP Control Panel will not stop any PHP processes that have been started. These php-cgi.exe processes will need to be killed in Task Manager. This is only a problem if you need to restart PHP, for example if you update php.ini.

References:

https://pimcore.com/docs/5.x/Development_Documentation/Installation_and_Upgrade/System_Setup_and_Hosting/Fix_Performance_Issues_with_XAMPP_on_Windows.html

http://www.sintesisdigital.com.mx/dashboard/docs/use-php-fcgi.html

https://www.apachelounge.com/download/

https://gist.github.com/basilfx/51cea37d10f4f4d68c74681d01f72e07

15 views

Need help? Let me take of your IT issues.

Share this page

Share on facebook
Share on linkedin
Share on twitter
Share on print
Share on email
Close Menu