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:
https://rabbitmq.com/install-homebrew.html
After installing rabbitmq and adding it to your path, you can then follow these steps found in this URL:
https://blog.karatos.in/a?ID=00850-2e534416-7a8d-4bce-b77c-ea946f63e10c
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.
$ cd/Users/***/Downloads/amqp-<VERSION>/amqp-<VERSION>
$ phpize
$ ./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
$ 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:
[ampq]
extension="amqp.so"
Save the file and restart php.
$ brew services restart php
Next, check if it amqp is installed successfully:
$ php -i|grep amqp
Happy hacking ๐
References
Top comments (1)
Have you tried ServBay.dev?
It's a much easier tool for PHP developers, providing a user-friendly experience, especially for beginners. It supports all versions of PHP, MariaDB, PostgreSQL, as well as Redis and Memcached. You can run multiple PHP instances simultaneously and switch between them effortlessly. It also offers easy updates without the need to configure environment variables. This tool has greatly simplified my PHP development and is definitely worth trying!