【PHP】phpbrewでPHPをインストールするときに発生したエラーとその解消方法

PHP

この記事ではphpbrewを使ってPHPをインストールしようとしたときに発生したエラーと、その解消方法を紹介します。

スポンサーリンク

phpbrewのバージョン

phpbrew version: 1.23.1

tar: Unrecognized archive format

“tar: Unrecognized archive format tar: Error exit delayed from previous errors.”

$ phpbrew install 7.1.27 +default

===> phpbrew will now build 7.1.27
===> Loading and resolving variants...
homebrew prefix '' doesn't exist. you forgot to install?
Checking distribution checksum...
Checksum mismatch: 68fd51e6451852b5ae2a9e32ca8d441006f9bdb497a2e385d28aab7bbedc015f != dad7ecd30941911528e471c555a01911a68aa9219696bfc1e005f8b669f4ec4b
Re-Downloading...
Downloading http://www.php.net/get/php-7.1.27.tar.bz2/from/this/mirror via curl extension
[==================================================================] 161.00/161.00B 100%
Redirecting to https://www.php.net/
===> Extracting /Users/foo/.phpbrew/distfiles/php-7.1.27.tar.bz2 to /Users/foo/.phpbrew/build/tmp.1553917057/php-7.1.27
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
Error: Extract failed:

このエラーはphpを “http://www.php.net” からダウンロードする際のプロトコルが、httpsではなくhttpになっているため発生するようです。

エラーの解消方法はphpのtarファイルを”~/.phpbrew/distfiles”にダウンロードしておくことです。

$ curl -L https://www.php.net/get/php-7.1.27.tar.bz2/from/this/mirror -o ~/.phpbrew/distfiles/php-7.1.27.tar.bz2

“phpbrew install”実行時にdistfilesにファイルが既に用意してあるので、ダウンロードを実行せずに処理が進むようになります。

$ phpbrew install 7.1.27 +default

configure: error: Please reinstall the BZip2 distribution

bzip2がインストールされていない場合は、brewでインストールします。

$ brew install bzip2

“+bz2=(brew –prefix bzip2)”を付けて”phpbrew install”を実行します。

※fishを使用しているため未確認ですが、bashやzshをお使いの場合、”$(brew –prefix”とカッコの前に”$”をつける必要があるかもしれません。

$ phpbrew install 7.1.27 +default+bz2=(brew --prefix bzip2)

Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located

zlibがインストールされていない場合はbrewでインストールします。

$ brew install zlib

“– –with-zlib-dir=(brew –prefix zlib)”を付けて”phpbrew install”を実行します。

※fishを使用しているため未確認ですが、bashやzshをお使いの場合、”$(brew –prefix”とカッコの前に”$”をつける必要があるかもしれません。

$ phpbrew install 7.1.27 +default+bz2=(brew --prefix bzip2) -- --with-zlib-dir=(brew --prefix zlib)

Please check your autoconf installation and the $PHP_AUTOCONF environment variable.

autoconfがインストールされていない場合はbrewでインストールします。

$ brew install autoconf