PHP Installation & Configuration

PHP 扩展指引

OS 扩展安装位置
Ubuntu /usr/lib/php
CentOS
macOS /usr/local/lib/php/pecl

Redis

pecl install redis

4.3.0@macOS

/bin/sh /private/tmp/pear/temp/pear-build-ma3310iiBwMh/redis-4.3.0/libtool --mode=compile cc  -I. -I/private/tmp/pear/temp/redis -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-ma3310iiBwMh/redis-4.3.0/include -I/private/tmp/pear/temp/pear-build-ma3310iiBwMh/redis-4.3.0/main -I/private/tmp/pear/temp/redis -I/usr/local/Cellar/php/7.4.11/include/php -I/usr/local/Cellar/php/7.4.11/include/php/main -I/usr/local/Cellar/php/7.4.11/include/php/TSRM -I/usr/local/Cellar/php/7.4.11/include/php/Zend -I/usr/local/Cellar/php/7.4.11/include/php/ext -I/usr/local/Cellar/php/7.4.11/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /private/tmp/pear/temp/redis/redis.c -o redis.lo
mkdir .libs
 cc -I. -I/private/tmp/pear/temp/redis -DPHP_ATOM_INC -I/private/tmp/pear/temp/pear-build-ma3310iiBwMh/redis-4.3.0/include -I/private/tmp/pear/temp/pear-build-ma3310iiBwMh/redis-4.3.0/main -I/private/tmp/pear/temp/redis -I/usr/local/Cellar/php/7.4.11/include/php -I/usr/local/Cellar/php/7.4.11/include/php/main -I/usr/local/Cellar/php/7.4.11/include/php/TSRM -I/usr/local/Cellar/php/7.4.11/include/php/Zend -I/usr/local/Cellar/php/7.4.11/include/php/ext -I/usr/local/Cellar/php/7.4.11/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /private/tmp/pear/temp/redis/redis.c  -fno-common -DPIC -o .libs/redis.o
In file included from /private/tmp/pear/temp/redis/redis.c:30:
In file included from /private/tmp/pear/temp/redis/redis_commands.h:5:
/private/tmp/pear/temp/redis/library.h:25:72: error: unknown type name 'ulong'
int redis_cmd_append_sstr_arrkey(smart_string *cmd, zend_string *kstr, ulong idx);
                                                                       ^
/private/tmp/pear/temp/redis/redis.c:1931:10: error: expected ';' after expression
    ulong idx;
         ^
         ;
/private/tmp/pear/temp/redis/redis.c:1931:5: error: use of undeclared identifier 'ulong'
    ulong idx;
    ^
/private/tmp/pear/temp/redis/redis.c:1931:11: error: use of undeclared identifier 'idx'
    ulong idx;
          ^
/private/tmp/pear/temp/redis/redis.c:1950:39: error: use of undeclared identifier 'idx'
    ZEND_HASH_FOREACH_KEY_VAL(htargs, idx, zkey,  zmem) {
                                      ^
/private/tmp/pear/temp/redis/redis.c:1955:62: error: use of undeclared identifier 'idx'
            keylen = snprintf(buf, sizeof(buf), "%ld", (long)idx);
                                                             ^
6 errors generated.
make: *** [redis.lo] Error 1
ERROR: `make' failed

最新的 macOS 的 cLang 没有定义 ulong 类型,会出现以上错误,参考以下方法设置 EXTRA_CFLAGS 补充定义可以解决:

export EXTRA_CFLAGS='-Dulong="unsigned long int"'
brew install liblzf
pecl install igbinary
brew install zstd
pecl install redis-4.3.0 # 安装指定版本扩展

5.x

5.x 以后的版本会出现 Delete 错误:

Deprecated function: Function Redis::delete() is deprecated 

除错

Redis 类没找到

PHP Fatal error:  Uncaught Error: Class 'Redis' not found in sites/all/modules/contrib/redis/lib/Redis/Client/PhpRedis.php:9
Stack trace:
#0 sites/all/modules/contrib/redis/lib/Redis/Client/Manager.php(142): Redis_Client_PhpRedis->getClient(Array)
#1 sites/all/modules/contrib/redis/lib/Redis/Client/Manager.php(85): Redis_Client_Manager->createClient('default')
#2 sites/all/modules/contrib/redis/lib/Redis/Client.php(213): Redis_Client_Manager->getClient()
#3 sites/all/modules/contrib/redis/lib/Redis/Cache.php(178): Redis_Client::getClient()
#4 includes/cache.inc(32): Redis_Cache->__construct('cache_bootstrap')
#5 includes/cache.inc(57): _cache_get_object('cache_bootstrap')
#6 includes/module.inc(762): cache_get('module_implemen...', 'cache_bootstrap')
#7 in sites/all/modules/contrib/redis/lib/Redis/Client/PhpRedis.php on line 9
Drush command terminated abnormally due to an unrecoverable error.                                                                                                                                                                                   [error]
Error: Uncaught Error: Class 'Redis' not found in sites/all/modules/contrib/redis/lib/Redis/Client/PhpRedis.php:9
Stack trace:
#0 sites/all/modules/contrib/redis/lib/Redis/Client/Manager.php(142): Redis_Client_PhpRedis->getClient(Array)
#1 sites/all/modules/contrib/redis/lib/Redis/Client/Manager.php(85): Redis_Client_Manager->createClient('default')
#2 sites/all/modules/contrib/redis/lib/Redis/Client.php(213): Redis_Client_Manager->getClient()
#3 sites/all/modules/contrib/redis/lib/Redis/Cache.php(178): Redis_Client::getClient()
#4 includes/cache.inc(32): Redis_Cache->__construct('cache_bootstrap')
#5 includes/cache.inc(57): _cache_get_object('cache_bootstrap')
#6 includes/module.inc(762): cache_get('module_implemen...', 'cache_bootstrap')
#7  in sites/all/modules/contrib/redis/lib/Redis/Client/PhpRedis.php, line 9

确认使用的 PHP 解释器安装了 redis.so 扩展。Brew 更新 PHP 后可能升级了主版本,对应的扩展需要重新安装,或者指定默认解释器的版本。

brew link --overwrite php@7.4

常见错误

PECL 命令失败

Notice: Undefined variable: proxy_host in Proxy.php on line 167
PHP Notice:  Undefined variable: proxy_host in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167
PHP Stack trace:
PHP   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
PHP   2. require_once() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
PHP   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
PHP   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
PHP   5. PEAR_Command_Remote->_checkChannelForStatus() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:317
PHP   6. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:176
PHP   7. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411

Notice: Undefined variable: proxy_host in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167

Call Stack:
    0.0005     418040   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
    0.0018     485952   2. require_once('/usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php') /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
    0.0261    1957248   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
    0.0261    1957248   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
    0.0341    2602672   5. PEAR_Command_Remote->_checkChannelForStatus() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:317
    0.0342    2603560   6. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:176
    0.0345    2604560   7. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411


Notice: Undefined variable: proxy_port in Proxy.php on line 167
PHP Notice:  Undefined variable: proxy_port in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167
PHP Stack trace:
PHP   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
PHP   2. require_once() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
PHP   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
PHP   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
PHP   5. PEAR_Command_Remote->_checkChannelForStatus() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:317
PHP   6. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:176
PHP   7. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411

Notice: Undefined variable: proxy_port in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167

Call Stack:
    0.0005     418040   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
    0.0018     485952   2. require_once('/usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php') /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
    0.0261    1957248   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
    0.0261    1957248   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
    0.0341    2602672   5. PEAR_Command_Remote->_checkChannelForStatus() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:317
    0.0342    2603560   6. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:176
    0.0345    2604560   7. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411


Notice: Undefined variable: proxy_host in Proxy.php on line 167
PHP Notice:  Undefined variable: proxy_host in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167
PHP Stack trace:
PHP   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
PHP   2. require_once() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
PHP   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
PHP   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
PHP   5. PEAR_REST_11->listAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:325
PHP   6. PEAR_REST->retrieveData() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST/11.php:47
PHP   7. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:87
PHP   8. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411

Notice: Undefined variable: proxy_host in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167

Call Stack:
    0.0005     418040   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
    0.0018     485952   2. require_once('/usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php') /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
    0.0261    1957248   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
    0.0261    1957248   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
   15.2469    2638152   5. PEAR_REST_11->listAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:325
   15.2469    2638232   6. PEAR_REST->retrieveData() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST/11.php:47
   15.2470    2638232   7. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:87
   15.2471    2639120   8. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411


Notice: Undefined variable: proxy_port in Proxy.php on line 167
PHP Notice:  Undefined variable: proxy_port in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167
PHP Stack trace:
PHP   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
PHP   2. require_once() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
PHP   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
PHP   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
PHP   5. PEAR_REST_11->listAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:325
PHP   6. PEAR_REST->retrieveData() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST/11.php:47
PHP   7. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:87
PHP   8. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411

Notice: Undefined variable: proxy_port in /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Proxy.php on line 167

Call Stack:
    0.0005     418040   1. {main}() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:0
    0.0018     485952   2. require_once('/usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php') /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/peclcmd.php:32
    0.0261    1957248   3. PEAR_Command_Remote->run() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/pearcmd.php:317
    0.0261    1957248   4. PEAR_Command_Remote->doListAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Common.php:270
   15.2469    2638152   5. PEAR_REST_11->listAll() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/Command/Remote.php:325
   15.2469    2638232   6. PEAR_REST->retrieveData() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST/11.php:47
   15.2470    2638232   7. PEAR_REST->downloadHttp() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:87
   15.2471    2639120   8. PEAR_Proxy->openSocket() /usr/local/Cellar/php@7.4/7.4.14_1/share/php@7.4/pear/PEAR/REST.php:411

Connection to `:' failed: Operation timed out

解决方案

用 pear.conf.default 重置 PECL 配置文件 pear.conf。配置文件位置参考以下表格:

操作系统 路径
macOS /usr/local/etc/php/7.4/
Author: njun
njun's picture
Updated: 2021/01/29