Ubuntu 14.04系统下为PHP 7.1安装phpredis的求助
Getting phpredis Working with PHP 7.1.15 on Ubuntu 14.04
Hey there, let's walk through getting phpredis properly installed and loaded for your setup. First, here's your PHP environment info for reference:
PHP 7.1.15-1+ubuntu14.04.1+deb.sury.org+2 (cli) (built: Mar 6 2018 11:51:39) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans with Zend OPcache v7.1.15-1+ubuntu14.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies
You mentioned trying both PECL and manual installs—let's break down the critical steps for each that are easy to overlook, plus some troubleshooting tips.
PECL Installation: Verify Configuration & Loading
You ran sudo pecl install redis and restarted php7.1-fpm, but extensions often fail to load because the PHP config isn't updated. Here's what to check:
- Add the extension to your PHP configs: After PECL finishes, it usually tells you to add
extension=redis.soto your PHP ini files. Runphp -i | grep "Loaded Configuration File"to find your CLI php.ini path. For PHP-FPM, look in/etc/php/7.1/fpm/php.inior theconf.dsubdirectory (creating a separate file like/etc/php/7.1/fpm/conf.d/20-redis.inihere is cleaner). - Confirm the extension is loaded:
- For CLI: Run
php -m | grep redis—if you seeredisprinted, it's loaded. - For FPM: Create a simple
phpinfo.phpfile with<?php phpinfo(); ?>, host it, and search for "redis" in the output. If it's missing, the FPM config wasn't updated or restarted properly.
- For CLI: Run
- Check FPM logs: If restarting FPM didn't help, look at
/var/log/php7.1-fpm.logfor errors about missingredis.soor invalid paths.
Manual Compilation: Fix Common Pitfalls
If the manual install from source didn't work, make sure you're using the correct tools for your PHP 7.1 setup:
- Install build dependencies first: You'll need development tools for PHP. Run
sudo apt-get install php7.1-dev build-essential—this installsphpize,php-config, and compiler tools. - Use the correct PHP 7.1 utilities: When compiling, specify the exact
phpizeandphp-configfor 7.1 to avoid targeting the wrong PHP version:phpize7.1 ./configure --with-php-config=/usr/bin/php-config7.1 make && sudo make install - Same config step as PECL: After compiling and installing, add
extension=redis.soto both CLI and FPM configs, then restart FPM.
Troubleshooting Common Issues
- "redis.so not found" errors: Find your extension directory with
php -i | grep extension_dir(it'll look like/usr/lib/php/20160303/for PHP 7.1). Then update your ini file to use the full path:extension=/usr/lib/php/20160303/redis.so. - Deb.sury.org source quirks: Ubuntu 14.04 with the sury repo sometimes has non-standard extension paths—always use
php -ito confirm the correct directory instead of guessing.
内容的提问来源于stack exchange,提问作者Michael Millar
相关产品推荐
相关产品推荐

