0

How to install the libevent extension for php on Centos 7?

I spent many many hours trying this, googling many times and really really struggled, so I'm going to document my own answer to this in the hope I help someone else.

I tried firstly on a MAC where I was attempting something along the lines of:

phpize
sh autogen.sh
./configure && make
sudo make install

I never actually achieved this way, running into many errors on the way, so I installed Centos and used yum to finally get the extension working. If anyone can explain the above method as well, that would be great.

2

php-pecl-event is available via the EPEL repository, built against the stock version of PHP.

Enable EPEL:

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install the PECL module:

yum install php-pecl-event
  • Great! Is there an alternative for Homebrew / Port do you know so I can get it installed on MacOSX Capitan as well? – Jonathan Clark Feb 24 '16 at 10:51
  • No idea, I don't use Mac. – carlwgeorge Feb 24 '16 at 16:24
  • I found you can install PECL on mac using curl -O http://pear.php.net/go-pear.phar and sudo php -d detect_unicode=0 go-pear.phar then from there you can install pecl install libevent-devel and Pecl install channel://pecl.php.net/libevent-0.1.0 – Jonathan Clark Feb 24 '16 at 17:32
1

I have listed all the steps as if you have selected 'minimum installation' for Centos 7, that way I should cover most people's setups on Centos, as no dependencies are assumed. I'm not a Linux guru, so some steps may seem unnecessary.

Yum install net-tools. - Allows ifconfig to check IP address (useful if it's a local VM).

Yum install php - Installs php version 5.4.16 (you might have an error with PHP 5.5 and greater. You can check what php version will be installed by running yum info php

Yum install php-mysql - Installs mysql and the pdo extensions php requires for many things.

yum install php-pear - install php-pear installing pear allows pecl command.

Yum install php-devel - To install libevent, you will need the command phpize, php-devel contains this.

Yum install gcc - You will also need C compiler to install libevent, which gcc provides.

Yum install libevent-devel - This installs the libevent ‘headers’ that pecl install libevent requires.

Pecl install libevent - This will actually result in error, but is useful in giving you the channel url to use instead, currently channel://pecl.php.net/libevent-0.1.0

Pecl install channel://pecl.php.net/libevent-0.1.0 - This is the final step that will (hopefully) install libevent without any errors.

Add extension=libevent.so to php.ini - Although libevent is installed, you need to tell php to reference it on startup.

Apachectl restart - Restarts apache / php

sudo iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT - this will allow connections from web browser.

Can now check it’s there by looking up ‘libevent’ by running <?php phpinfo(); ?> By default, web files should go in /var/www/html.

  • php-pear is in the base EL7 repos, there is no need to get it from remirepo. Since you already started installing stock php packages, you should stick with stock. – carlwgeorge Feb 24 '16 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.