Install the PHP AMQP extension
The AMQP extension provides PHP functions for communicating with AMQP-compatible servers such as RabbitMQ.
The AMQP extension supports PHP 5.6+. To use the latest version of the AMPQ extension, you will need PHP 7.4+.
Install the AMQP extension
Installing the extension involves the following steps:
- Install build dependencies (packages that are required to build the extension).
- Build the extension’s library file.
- Enable the extension in the PHP configuration.
Install build dependencies
Set environment variables for the package manager.
export DEBIAN_FRONTEND=noninteractive
Install a compiler and other packages that are required for building PHP extensions.
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config
Install additional packages that are required to build the AMQP extension.
sudo apt-get -y install libssl-dev librabbitmq-dev
Build the extension
The PECL install
command compiles the extension’s .so
library file.
yes '' | sudo pecl8.4-sp install amqp
yes '' | sudo pecl8.3-sp install amqp
yes '' | sudo pecl8.2-sp install amqp
yes '' | sudo pecl8.1-sp install amqp
yes '' | sudo pecl8.0-sp install amqp
yes '' | sudo pecl7.4-sp install amqp
yes '' | sudo pecl7.3-sp install amqp-1.11.0
yes '' | sudo pecl7.2-sp install amqp-1.11.0
yes '' | sudo pecl7.1-sp install amqp-1.11.0
yes '' | sudo pecl7.0-sp install amqp-1.11.0
yes '' | sudo pecl5.6-sp install amqp-1.11.0
Enable the extension
Configure PHP to load the extension.
sudo bash -c "echo extension=amqp.so > /etc/php8.4-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php8.3-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php8.2-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php8.1-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php8.0-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php7.4-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php7.3-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php7.2-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php7.1-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php7.0-sp/conf.d/amqp.ini"
sudo bash -c "echo extension=amqp.so > /etc/php5.6-sp/conf.d/amqp.ini"
Restart PHP-FPM.
sudo service php8.4-fpm-sp restart
sudo service php8.3-fpm-sp restart
sudo service php8.2-fpm-sp restart
sudo service php8.1-fpm-sp restart
sudo service php8.0-fpm-sp restart
sudo service php7.4-fpm-sp restart
sudo service php7.3-fpm-sp restart
sudo service php7.2-fpm-sp restart
sudo service php7.1-fpm-sp restart
sudo service php7.0-fpm-sp restart
sudo service php5.6-fpm-sp restart
Verify the extension is enabled in PHP.
php8.4-sp -i | grep amqp
php8.3-sp -i | grep amqp
php8.2-sp -i | grep amqp
php8.1-sp -i | grep amqp
php8.0-sp -i | grep amqp
php7.4-sp -i | grep amqp
php7.3-sp -i | grep amqp
php7.2-sp -i | grep amqp
php7.1-sp -i | grep amqp
php7.0-sp -i | grep amqp
php5.6-sp -i | grep amqp
If the extension is enabled, you will see output like the following.
Additional .ini files parsed => /etc/phpX.Y-sp/conf.d/amqp.ini,amqpamqp.auto_ack => 0 => 0amqp.cacert => no value => no valueamqp.cert => no value => no valueamqp.channel_max => 256 => 256amqp.connect_timeout => 0 => 0amqp.deserialization_depth => 128 => 128amqp.frame_max => 131072 => 131072amqp.global_prefetch_count => 0 => 0amqp.global_prefetch_size => 0 => 0amqp.heartbeat => 0 => 0amqp.host => localhost => localhostamqp.key => no value => no valueamqp.login => guest => guestamqp.password => guest => guestamqp.port => 5672 => 5672amqp.prefetch_count => 3 => 3amqp.prefetch_size => 0 => 0amqp.read_timeout => 0 => 0amqp.rpc_timeout => 0 => 0amqp.sasl_method => AMQP_SASL_METHOD_PLAIN => AMQP_SASL_METHOD_PLAINamqp.serialization_depth => 128 => 128amqp.timeout => no value => no valueamqp.verify => 1 => 1amqp.vhost => / => /amqp.write_timeout => 0 => 0
Uninstall the AMQP extension
Uninstalling the extension involves the following steps:
- Disable the extension in the PHP configuration.
- Remove the extension’s library file.
Disable the extension
Remove the extension’s configuration from PHP.
sudo rm /etc/php8.4-sp/conf.d/amqp.ini
sudo rm /etc/php8.3-sp/conf.d/amqp.ini
sudo rm /etc/php8.2-sp/conf.d/amqp.ini
sudo rm /etc/php8.1-sp/conf.d/amqp.ini
sudo rm /etc/php8.0-sp/conf.d/amqp.ini
sudo rm /etc/php7.4-sp/conf.d/amqp.ini
sudo rm /etc/php7.3-sp/conf.d/amqp.ini
sudo rm /etc/php7.2-sp/conf.d/amqp.ini
sudo rm /etc/php7.1-sp/conf.d/amqp.ini
sudo rm /etc/php7.0-sp/conf.d/amqp.ini
sudo rm /etc/php5.6-sp/conf.d/amqp.ini
Restart PHP-FPM.
sudo service php8.4-fpm-sp restart
sudo service php8.3-fpm-sp restart
sudo service php8.2-fpm-sp restart
sudo service php8.1-fpm-sp restart
sudo service php8.0-fpm-sp restart
sudo service php7.4-fpm-sp restart
sudo service php7.3-fpm-sp restart
sudo service php7.2-fpm-sp restart
sudo service php7.1-fpm-sp restart
sudo service php7.0-fpm-sp restart
sudo service php5.6-fpm-sp restart
Remove the extension
The PECL uninstall
command removes the extension’s .so
library file.
sudo pecl8.4-sp uninstall amqp
sudo pecl8.3-sp uninstall amqp
sudo pecl8.2-sp uninstall amqp
sudo pecl8.1-sp uninstall amqp
sudo pecl8.0-sp uninstall amqp
sudo pecl7.4-sp uninstall amqp
sudo pecl7.3-sp uninstall amqp
sudo pecl7.2-sp uninstall amqp
sudo pecl7.1-sp uninstall amqp
sudo pecl7.0-sp uninstall amqp
sudo pecl5.6-sp uninstall amqp