How to Install the PHP AMQP Extension

To install a PECL extension for multiple PHP versions, repeat the PECL extension installation for each PHP version.
The PHP AMQP extension requires Ubuntu 16.04. This extension will not work on Ubuntu 14.04 as the extension requires a newer version of the librabbitmq library than Ubuntu supports on 14.04.

The PHP AMQP extension provides PHP functions for communicating with AMQP-compatible servers, such as RabbitMQ.

Installing the AMQP Extension

In the examples shown, replace "X.Y" with your app's PHP version (for example, "7.0").

To install the PHP AMQP extension, SSH in to your server as root and first run the following commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libssl-dev
sudo apt-get -y install librabbitmq-dev

Next, run the following command:

sudo peclX.Y-sp install amqp

When you receive this prompt:

Set the path to librabbitmq install prefix [autodetect] :

press Enter without entering a prefix. This allows the library's location to be autodetected.

Once installed, create a configuration file for the extension and restart PHP by running the following command as root:

sudo bash -c "echo > /etc/phpX.Y-sp/conf.d/amqp.ini"
sudo service phpX.Y-fpm-sp restart

Verifying the PHP AMQP Extension Is Installed

You can verify the AMQP extension is installed by running this command:

phpX.Y-sp -i | grep -i amqp

You should see output similar to the following:

Additional .ini files parsed => /etc/php7.1-sp/conf.d/amqp.ini,
AMQP protocol version => 0-9-1
amqp.auto_ack => 0 => 0
amqp.channel_max => 256 => 256
amqp.connect_timeout => 0 => 0
amqp.frame_max => 131072 => 131072
amqp.heartbeat => 0 => 0 => localhost => localhost
amqp.login => guest => guest
amqp.password => guest => guest
amqp.port => 5672 => 5672
amqp.prefetch_count => 3 => 3
amqp.read_timeout => 0 => 0
amqp.timeout => no value => no value
amqp.vhost => / => /
amqp.write_timeout => 0 => 0

Uninstalling the AMQP Extension

To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/amqp.ini
sudo peclX.Y-sp uninstall amqp

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart

Last updated: October 03, 2016