2

I installed the libevent-dev library on my Debian 7 64bit desktop:

$ sudo aptitude install -y libevent-dev

Then I installed the PECL library

$ pecl list
Installed packages, channel pecl.php.net:
=========================================
Package  Version State
libevent 0.1.0   beta

I've restarted PHP and the OS but PHP doesn't list libevent as an installed ext in with phpinfo() and I get "PHP Fatal error: Call to undefined function event_base_new()" when I try to use it.

How do you install Libevent?

Xeoncross
  • 55,620
  • 80
  • 262
  • 364
  • A [related question](http://serverfault.com/questions/271554/problems-installing-php-libevent-pecl-package) which the solution didn't work. – Xeoncross Apr 21 '14 at 18:11

3 Answers3

9

Install Libevent for PHP 5.X

sudo apt-get install libevent-dev
sudo pecl install libevent-beta

sudo su
sudo echo 'extension=libevent.so' > /etc/php5/mods-available/libevent.ini
exit

sudo ln -s /etc/php5/mods-available/libevent.ini /etc/php5/fpm/conf.d/
sudo ln -s /etc/php5/mods-available/libevent.ini /etc/php5/cli/conf.d/

sudo service php5-fpm restart

Install Libevent for PHP 7.X

At this time pecl package libevent is not available for php 7

https://pecl.php.net/package/libevent

So let's compile it.

Download master: https://github.com/expressif/pecl-event-libevent

Unpack to: /tmp/install_libevent

cd /tmp/install_libevent/pecl-event-libevent-master
sudo phpize
sudo ./configure

After this step scroll our console window and try find any Warnings or Errors. I got one warning - required to install re2c package.

sudo make
sudo make install

sudo su
sudo echo 'extension=libevent.so' > /etc/php/7.0/mods-available/libevent.ini
exit

sudo ln -s /etc/php/7.0/mods-available/libevent.ini /etc/php/7.0/fpm/conf.d/20-libevent.ini
sudo ln -s /etc/php/7.0/mods-available/libevent.ini /etc/php/7.0/cli/conf.d/20-libevent.ini

sudo service php7.0-fpm restart
sNICkerssss
  • 6,312
  • 1
  • 24
  • 16
2

I've successfully installed it. These are the steps:

apt-get install libevent-dev 
sudo pecl install libevent

Edit: Press enter when you are asked for the libevent installation directory (autodetect)

; Add extension=libevent.so in the *.ini file where you desire to load it. For example if you want this extension to be loaded always, create a libevent.ini file where your php5 mods are (in my computer they are in /etc/php5/mods-available/) and write extension=libevent.so. Enable this module then with php5enmod libevent. This page may help you.

vicaba
  • 2,836
  • 1
  • 27
  • 45
0

Add extension=libevent.so to php.ini.

Nataraj
  • 379
  • 7
  • 18
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Ahmad Dwaik 'Warlock' Apr 29 '14 at 13:18
  • Edited my answer. I intended to add the clarification as a comment. Since I do not have enough reputation, I had no other go but to post it as an answer. – Nataraj Apr 30 '14 at 05:48