How to compile a PHP extension like Redis, under Windows. Since nobody really explains that.
Run commands under the old Windows shell, e.g. cmd.exe
You will need the 2019 version of the Microsoft C/C++ compiler, so the linker is compatible with the downloadable PHP for Windows. winget
can found as "App Installer" in the Windows Store.
winget install --id Microsoft.VisualStudio.2022.BuildTools
In the Visual Studio Build Tools 2022 'modify' the install under the 'Individual components' tab, and select:
- C++/CLI support for v142 build tools (14.29-16.11)
- MSVC v142 - VS 2019 C++ x64/x86 build tools
Download PHP for Windows, also download and unzip the 'Development package (SDK to develop PHP extensions)' and probable also the 'Debug Pack'. In the 'Development package' there is a folder, you need to unzip the contents of that folder to the folder where you have php.exe
. https://windows.php.net/download#php-8.2
Git clone https://github.com/phpredis/phpredis inside the folder where you have php.exe
.
winget install --id Git.Git
git clone https://github.com/phpredis/phpredis.git
# or:
winget install --id Git.Git
winget install --id GitHub.cli
gh repo clone phpredis/phpredis
You might want to switch away from the main develop
branch:
git tag # find the latest non-RC version, currently that is 5.3.7
git checkout 5.3.7
In a command shell cmd.exe
inside the directory where you have php.exe
.
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.29
cd phpredis
..\phpize.bat
.\configure.bat --enable-redis --with-prefix=%cd%\..
Check that in the Makefile PHP_PREFIX
and PHP_SRC_DIR
point to the directory holding php.exe and the phpredis source code, e.g.
PHP_SRC_DIR ="C:\laragon\bin\php\php-8.2.7-Win32-vs16-x64\phpredis"
PHP_PREFIX="C:\laragon\bin\php\php-8.2.7-Win32-vs16-x64\"
Then build with:
nmake clean
nmake
copy x64\Release_TS\php_redis.dll ..\ext\
In the php.ini:
extension=php_redis.dll
Then run php -m
to see redis listed.
releases/6.0.2
) → click on the green "✔" next to commit message → click on "Details" next to anyci.yml
job → click on "Summary" in the left sidebar → scroll down to the "Artifacts" section → download desired version – Luck