Current Location: Home> Latest Articles> Complete Guide to Efficiently Installing Event Extension in PHP7

Complete Guide to Efficiently Installing Event Extension in PHP7

gitbox 2025-08-09

Preparation Before Installation

Before installing the event extension for PHP, you need to make sure the libevent library is already installed on your system, as the event extension depends on it for event-driven functionality.

Installing the libevent Library

libevent is a cross-platform event notification library that supports various event mechanisms. You can download the latest stable source package from its official website.

tar zxvf libevent-2.1.8-stable.tar.gz
cd libevent-2.1.8-stable
./configure
make
sudo make install

Obtaining the Event Extension

The event extension can be installed via the PECL tool or downloaded from repositories such as GitHub for the latest source code.

sudo pecl install event-2.3.0

If you encounter errors indicating that the libevent library cannot be found during installation, you need to manually set the libevent installation paths using the following PECL configuration commands:

sudo pecl config-set bin_dir /usr/local/bin/
sudo pecl config-set php_ini /etc/php.ini
sudo pecl config-set php_dir /usr/share/php/
sudo pecl config-set ext_dir "$(php-config --extension-dir)"
sudo pecl config-set include_dir /usr/local/include/
sudo pecl config-set library_dir /usr/local/lib/

If you prefer to install from source manually, use the following commands:

sudo pecl download event
tar zxvf event-x.y.z.tgz
cd event-x.y.z

Compiling and Installing the Event Extension

phpize
./configure
make
sudo make install

Enabling the Event Extension

Edit your php.ini file and add the following line to enable the event extension:

extension=event.so

Verifying Successful Installation

Run the following command to check if the event extension is properly loaded:

php -i | grep event

If relevant output appears, the event extension has been installed and enabled successfully.