I spent several hours trying to set up PHP amqp extension on mac. When I finally got it to work, I created this post as a reference for myself in the future, and also to assist anyone trying to install it.
First, follow the usual steps to install rabbitmq from the URL:
After installing rabbitmq and adding it to your path, you can then follow these steps found in this URL:
The steps below are similar to the ones in the above URL, however, I had to modify it to make it work in my case.
Download the latest version of AMQP or any version of your choice from this URL: https://pecl.php.net/package/amqp
Extract the zipped file and visit it on your terminal.
$ ./configure -with-php-config=/opt/homebrew/bin/php-config --with-amqp --with-librabbitmq-dir=/opt/homebrew/Cellar/rabbitmq-c/<VERSION>
In my case, I ran the previous command with version 0.11.0 as seen below:
./configure -with-php-config=/opt/homebrew/bin/php-config --with-amqp --with-librabbitmq-dir=/opt/homebrew/Cellar/rabbitmq-c/0.11.0
Run the following commands:
$ make test
$ make install
That's it. amqp should be installed by now. Next, you have to add the extension to your PHP configuration.
Open the php.ini file at /opt/homebrew/etc/php/8.1/php.ini, if the extension have been added (extension="amqp.so"), remove it and create ext-amqp.ini in the folder /opt/homebrew/etc/php/8.1/conf.d and add the following content:
Save the file and restart php.
$ brew services restart php
Next, check if it amqp is installed successfully:
$ php -i|grep amqp
Happy hacking 🚀