読者です 読者をやめる 読者になる 読者になる

わすれっぽいきみえ

みらいのじぶんにやさしくしてやる

php7より古いphpにredis拡張をphpbrewで入れようとするとエラー

phpbrewで5.6のphpをinstallしたが、その後redisの拡張が入らなかった。

$ phpbrew ext install redis
Downloading http://pecl.php.net/get/redis-3.0.0.tgz via curl extension
[==================================================================] 185.27/185.27KB 100%
===> Extracting to /Users/kimikimi714/.phpbrew/build/php-5.6.15/ext...
===> Installing redis extension...
Log stored at: /Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis/build.log
Changing directory to /Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis
===> Phpize...
===> Configuring...
===> Building...
===> Running make all: /usr/bin/make -C '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis' 'all'  >> '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis/build.log' 2>&1
Exception: Command failed: /usr/bin/make -C '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis' 'all'  >> '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis/build.log' 2>&1 returns
Trace:

0) PhpBrew\Utils::system(['/usr/bin/make', '-C', '\'/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis\'', '\'all\'', ' >> \'/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis/build.log\' 2>&1'], CLIFramework\Logger)
  1) PhpBrew\Tasks\MakeTask->make('/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis', 'all')
  2) PhpBrew\Tasks\MakeTask->run(PhpBrew\Extension\PeclExtension)
  3) PhpBrew\Extension\ExtensionInstaller->install(PhpBrew\Extension\PeclExtension, [])
4) PhpBrew\Extension\ExtensionManager->installExtension(PhpBrew\Extension\PeclExtension, [])
  5) PhpBrew\Command\ExtensionCommand\InstallCommand->execute('redis', 'stable')
  6) call_user_func_array([PhpBrew\Command\ExtensionCommand\InstallCommand, 'execute'], ['redis', 'stable'])
  7) CLIFramework\CommandBase->executeWrapper(['redis', 'stable'])
  8) CLIFramework\Application->run(['/usr/local/Cellar/phpbrew/1.21.1/libexec/phpbrew.phar', 'ext', 'install', 'redis', 'stable'])
  9) CLIFramework\Application->runWithTry(['/usr/local/Cellar/phpbrew/1.21.1/libexec/phpbrew.phar', 'ext', 'install', 'redis', 'stable'])
  10) require('phar:///usr/local/Cellar/phpbrew/1.21.1/libexec/phpbrew.phar/scripts/phpbrew-emb.php')

なんでかなーと思って、調べたら

github.com

要するに最新のphp拡張であるredis-3.0.0はphp7以上でないと使えなくて、 ext/standard/php_smart_str.h ではなく ext/standard/php_smart_string.h を読み込もうとする。しかしphp5.6だとそんなファイルはないので死ぬとのことだった。

そこでまずpeclサイトからredisバージョン一覧を確認し

PECL :: Package :: redis

github.com

を見て、明示的にどのバージョンの拡張を入れるか指定する。

$ phpbrew ext install redis 2.2.8
Downloading http://pecl.php.net/get/redis-2.2.8.tgz via curl extension
[==================================================================] 187.63/187.63KB 100%
===> Extracting to /Users/kimikimi714/.phpbrew/build/php-5.6.15/ext...
===> Installing redis extension...
Log stored at: /Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis/build.log
Changing directory to /Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis
===> Phpize...
===> Configuring...
===> Building...
===> Running make all: /usr/bin/make -C '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis' 'all'  >> '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis/build.log' 2>&1
===> Installing...
===> Running make install: /usr/bin/make -C '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis' 'install'  >> '/Users/kimikimi714/.phpbrew/build/php-5.6.15/ext/redis/build.log' 2>&1
===> Extension is installed.
===> Creating config file /Users/kimikimi714/.phpbrew/php/php-5.6.15/var/db/redis.ini.disabled
===> Enabling extension redis
[*] redis extension is enabled.
Done.

通った。