Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Installing php7-fpm with phpredis and xdebug extension on Ubuntu 14.04

Install php7.0-fpm

# remove php5 modules
apt-get autoremove --purge php5-*
# add php-7.0 source list by [Ondřej Surý](https://github.com/oerdnj)
add-apt-repository ppa:ondrej/php
# Update index
apt-get update
# Install php7.0-fpm with needed extensions
apt-get install php7.0-fpm php7.0-cli php7.0-common php7.0-json php7.0-opcache php7.0-mysql php7.0-phpdbg php7.0-mbstring php7.0-gd php7.0-imap php7.0-ldap php7.0-pgsql php7.0-pspell php7.0-recode php7.0-snmp php7.0-tidy php7.0-dev php7.0-intl php7.0-gd php7.0-curl php7.0-zip php7.0-xml

UPDATE 2016-03-10

As mentioned by @jackmcpickle php-redis can now be installed with apt-get install php-redis and should be equivalent to the manual installation below. After installation phpinfo() says: Redis-Version 2.2.8-devphp7

Same with xdebug. apt-get install php-xdebug will install the newly released stable version 2.4.0 that has php7 support.

So the manual installations below are not needed any longer.


Build phpredis extension

git clone https://github.com/phpredis/phpredis.git
cd phpredis
git checkout php7
phpize
./configure
make && make install
cd ..
rm -rf phpredis

Activate phpredis extension in fpm and cli

echo "extension=redis.so" > /etc/php/7.0/mods-available/redis.ini

ln -sf /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/fpm/conf.d/20-redis.ini

ln -sf /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/cli/conf.d/20-redis.ini

service php7.0-fpm restart

nginx vhost config

Replace unix:/var/run/php5-fpm.sock with unix:/var/run/php/php7.0-fpm.sock

service nginx restart

Install xdebug extension

# Download stable release of xdebug 2.4.0
wget -c "http://xdebug.org/files/xdebug-2.4.0.tgz"
# Extract archive
tar -xf xdebug-2.4.0.tgz

cd xdebug-2.4.0/

# build extension
phpize
./configure
make && make install

Enable the extension:

echo "zend_extension=xdebug.so" > /etc/php/7.0/mods-available/xdebug.ini

ln -sf /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini
ln -sf /etc/php/7.0/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini

service php7.0-fpm restart

# Check it
php -m | grep -i xdebug

# should print:
xdebug
Xdebug
@jverdeyen

This comment has been minimized.

Show comment Hide comment
@jverdeyen

jverdeyen Dec 8, 2015

Nice one! I've also added php7.0-curl when using Guzzle.

Nice one! I've also added php7.0-curl when using Guzzle.

@emiglobetrotting

This comment has been minimized.

Show comment Hide comment
@emiglobetrotting

emiglobetrotting Jan 21, 2016

How to enable ZTS to support pthread in this installation?

How to enable ZTS to support pthread in this installation?

@hollodotme

This comment has been minimized.

Show comment Hide comment
@hollodotme

hollodotme Jan 28, 2016

AFAIK for enabling ZTS you need to build php on your own.

Owner

hollodotme commented Jan 28, 2016

AFAIK for enabling ZTS you need to build php on your own.

@tylermauthe

This comment has been minimized.

Show comment Hide comment
@tylermauthe

tylermauthe Feb 29, 2016

Can anyone comment on the stability of php-redis in PHP7? It looks like they haven't released a stable build yet...

Can anyone comment on the stability of php-redis in PHP7? It looks like they haven't released a stable build yet...

@hollodotme

This comment has been minimized.

Show comment Hide comment
@hollodotme

hollodotme Mar 2, 2016

Fixed ppa and mods-available path in redis section

Owner

hollodotme commented Mar 2, 2016

Fixed ppa and mods-available path in redis section

@hollodotme

This comment has been minimized.

Show comment Hide comment
@hollodotme

hollodotme Mar 5, 2016

Added how to enable stable xdebug 2.4.0 extension

Owner

hollodotme commented Mar 5, 2016

Added how to enable stable xdebug 2.4.0 extension

@jackmcpickle

This comment has been minimized.

Show comment Hide comment
@jackmcpickle

jackmcpickle Mar 9, 2016

We're using php-redis with php7.0 and seems to be running ok.

We're using php-redis with php7.0 and seems to be running ok.

@hollodotme

This comment has been minimized.

Show comment Hide comment
@hollodotme

hollodotme Mar 10, 2016

@tylermauthe Please see my update from 2016-03-10 above.
@jackmcpickle Thanks for sharing!

Owner

hollodotme commented Mar 10, 2016

@tylermauthe Please see my update from 2016-03-10 above.
@jackmcpickle Thanks for sharing!

@nandes2062

This comment has been minimized.

Show comment Hide comment
@nandes2062

nandes2062 Jul 16, 2016

buenisimo muchas gracias por el aporte

buenisimo muchas gracias por el aporte

@filipesiqueira

This comment has been minimized.

Show comment Hide comment
@filipesiqueira

filipesiqueira Dec 14, 2016

helped me a lot. thank you so much!

helped me a lot. thank you so much!

@wbconnor

This comment has been minimized.

Show comment Hide comment
@wbconnor

wbconnor Dec 20, 2016

For activating Redis extension with Apache2, I also had to do
sudo ln -sf /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/apache2/conf.d/20-redis.ini

For activating Redis extension with Apache2, I also had to do
sudo ln -sf /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/apache2/conf.d/20-redis.ini

@mamsysuser

This comment has been minimized.

Show comment Hide comment
@mamsysuser

mamsysuser Feb 8, 2017

Nice one...thanks

Nice one...thanks

@phpmongodb

This comment has been minimized.

Show comment Hide comment
@phpmongodb

phpmongodb May 16, 2017

Installing shared extensions: /usr/lib/php/20151012/
cp: cannot create regular file '/usr/lib/php/20151012/#INST@10102#': Permission denied
Makefile:87: recipe for target 'install-modules' failed
make: *** [install-modules] Error 1

Installing shared extensions: /usr/lib/php/20151012/
cp: cannot create regular file '/usr/lib/php/20151012/#INST@10102#': Permission denied
Makefile:87: recipe for target 'install-modules' failed
make: *** [install-modules] Error 1

@sachind

This comment has been minimized.

Show comment Hide comment
@sachind

sachind Jun 27, 2017

Thanks !

sachind commented Jun 27, 2017

Thanks !

@Panoptik

This comment has been minimized.

Show comment Hide comment
@Panoptik

Panoptik Jul 6, 2017

Instead of creating symlinks manualy it would be better to use native tool phpenmod
phpenmod -v 7.0 redis

Installing shared extensions: /usr/lib/php/20151012/
cp: cannot create regular file '/usr/lib/php/20151012/#INST@10102#': Permission denied
Makefile:87: recipe for target 'install-modules' failed
make: *** [install-modules] Error 1

make && sudo make install

Panoptik commented Jul 6, 2017

Instead of creating symlinks manualy it would be better to use native tool phpenmod
phpenmod -v 7.0 redis

Installing shared extensions: /usr/lib/php/20151012/
cp: cannot create regular file '/usr/lib/php/20151012/#INST@10102#': Permission denied
Makefile:87: recipe for target 'install-modules' failed
make: *** [install-modules] Error 1

make && sudo make install

@usmanhalalit

This comment has been minimized.

Show comment Hide comment
@usmanhalalit

usmanhalalit Oct 20, 2017

Thanks! That worked with PHP 7.1 too.

Thanks! That worked with PHP 7.1 too.

@stephane888

This comment has been minimized.

Show comment Hide comment
@stephane888

stephane888 Mar 10, 2018

Under certain conditions the following command does not work,
#apt-get install php-redis
#apt-get install php-xdebug
you must use (php 7.0)
#apt-get install php7.0-redis
#apt-get install php7.0-xdebug

Under certain conditions the following command does not work,
#apt-get install php-redis
#apt-get install php-xdebug
you must use (php 7.0)
#apt-get install php7.0-redis
#apt-get install php7.0-xdebug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment