Note: this is mainly for my own notes so I can remember what I did. If someone else finds this helpful, that’s cool too. If you just want to install the pre-built binary, you can skip down to the end.
One of our PHP developers uses Windows as his platform of choice for development work. We’ve just chosen RabbitMQ for our queuing system, and that left us in a bit of a pickle. The Installation instructions for the AMQP PECL extension contains the following warning:
Note to Windows users: This extension does not currently support Windows since the librabbitmq library does not yet support Windows.
There are two pure php implementations of AMQP, one being a fork of a (now abandoned) python module, the other being a fork of the first which updates it to allow connecting to AMQP 0.9.1. Neither of these are even remotely as well documented as the PECL extension. Also, the PECL extension is supposedly much faster, which is not surprising as the heavy lifting is done in compiled C versus interpreted PHP.
I decided to do a bit of digging to see if the AMQP PECL extension could be built on Windows easily. The AMQP pecl extension depends on the the RabbitMQ C library, which according to the README files currently supports Windows builds. Since PHP only officially supports builds using Visual Studio 2008, I downloaded the express version for my Windows VM here. Once installed, I also tracked down several dependencies outlined in the README.win32 file, namely mingw (downloaded from their script) and Python version 3.3.1. One of the dependencies I discovered that isn’t mentioned in the docs is OpensSSL for Windows. I also made sure that all of the above were listed in the path (OpenSSL, Python, mingw, CMake etc). Here’s where it gets a little bit confusing: Once you have your build environment configured, you ignore the rest of the README-win32.md and instead reference the CMAKE instructions listed in the main README.md file. Make sure you set a PREFIX when issuing the first cmake, then do the install target and specify the Release config. For example:
cmake -DCMAKE_INSTALL_PREFIX=c:/rabbitmq-c ..
cmake --build . --config Release --target install
Note this location for later (in this case, c:\rabbitmq-c).
Note: This library supports newer versions of Visual Studio, but PHP doesn’t officially support anything newer than 2008, so that’s why I compiled it using VS 2008.
Okay, so now we have a working build of the RabbitMQ C library for Windows. So I did some digging into the PECL extension itsself and discovered that the original author, Pieter de Zwart, had moved his code into github at https://github.com/pdezwart/php-amqp. Lo and behold, they have a build file for Visual Studio. I had to grab the HEAD revision of the master branch — commit a9fd1f33b18172f276d2893a10b4ff4c579f2c2b at the time of this writing — in order to get it to build cleanly, but indeed it does build on Windows. In order to build, I followed the instructions listed at https://wiki.php.net/internals/windows/stepbystepbuild to configure the build environment, including downloading the SDK version 6.1 from Microsoft, the downloads for the php sdk tools etc. I did not, however, use a snapshot version of the source code, opting instead for php 5.3.24 release source.
Following that Wiki, at step 11 where they mention the “deps” folder, I copied all of the files from the library install earlier, in the same folder structure that it installs, into the deps folder (include, bin, lib).
Once we get down to step 14 and run the configure –help, we should see –with-amqp as an option if all went well. If not, then make sure that you completed step 11 properly, then do a buildconf –force and configure –help again. Once you get the amqp extension recognized by buildconf, issue the following (in place of step 15):
configure --disable-all --enable-cli --with-amqp=shared
Then just do an nmake. If all goes well, you should have a php_amqp.dll file in the Release_TS directory.
Note: If you want to do a non-threadsafe build, in place of the above, issue the following:
configure --disable-all --enable-cli --with-amqp=shared --disable-zts
Once you complete that step, your dll will actually be found in the Release folder instead of Release_TS.
Note: this assumes a 32 bit build of php 5.3. This also assumes that you have the 32 bit Microsoft Visual C++ 2008 redistributable installed, which can be found here.
To install, copy rabbitmq.1.dll into the 32 bit library folder.
If you’ve compiled the dll yourself, it will be found, oddly enough, in the bin directory of the PREFIX path you specified earlier in the build.
If you want to download a precompiled binary, click here , and copy it into the 32 bit library folder.
The 32 bit library folder location will vary based on the Windows architecture. On 32 bit versions of Windows, this will be under c:\Windows\system32 . On 64 bit installs of Windows, this will be under c:\Windows\SysWOW64
Update your php.ini with:
Restart your web server, cross your fingers, and hopefully all went well!
If you’d rather download a zip file with all of the files referenced in this blog post, click here.