eureka

PHPのインストールで怒られた

0

Larabel開発を考えて環境構築をしていると、phpbrewでインストールできるはずの指定のバージョンのPHPがインストールできない。

この記事はエラー解決までのメモ。

PHP環境構築のほうはこちらの記事で。
Macにphpをインストールして開発環境を整える

PHPをインストールしようとするとエラーになる

PHPのバージョンリストを表示して、リスト内のPHPのバージョンをインストールする。

$ phpbrew known
===> Fetching release list...
Downloading https://secure.php.net/releases/index.php?json&version=7&max=100 via curl extension
Downloading https://secure.php.net/releases/index.php?json&version=5&max=100 via curl extension
7.3: 7.3.10, 7.3.9, 7.3.8, 7.3.7, 7.3.6, 7.3.5, 7.3.4, 7.3.3 ...
7.2: 7.2.23, 7.2.22, 7.2.21, 7.2.20, 7.2.19, 7.2.18, 7.2.17, 7.2.16 ...
7.1: 7.1.32, 7.1.31, 7.1.30, 7.1.29, 7.1.28, 7.1.27, 7.1.26, 7.1.25 ...
7.0: 7.0.33, 7.0.32, 7.0.31, 7.0.30, 7.0.29, 7.0.28, 7.0.27, 7.0.26 ...
5.6: 5.6.40, 5.6.39, 5.6.38, 5.6.37, 5.6.36, 5.6.35, 5.6.34, 5.6.33 ...
5.5: 5.5.38, 5.5.37, 5.5.36, 5.5.35, 5.5.34, 5.5.33, 5.5.32, 5.5.31 ...
5.4: 5.4.45, 5.4.44, 5.4.43, 5.4.42, 5.4.41, 5.4.40, 5.4.39, 5.4.38 ...

今回は7.1.21を選択する。

$ phpbrew install 7.1.21 +default +mysql

するとこんなエラーが出た。

===> phpbrew will now build 7.1.21
===> Loading and resolving variants...
Downloading http://www.php.net/get/php-7.1.21.tar.bz2/from/this/mirror via curl extension
[==================================================================] 177.00/177.00B 100%
Redirecting to https://www.php.net/get/php-7.1.21.tar.bz2/from/this/mirror
Redirecting to https://www.php.net/distributions/php-7.1.21.tar.bz2
[==================================================================] 14.47/14.47MB 100%
===> Extracting /Users/xxxxxx/.phpbrew/distfiles/php-7.1.21.tar.bz2 to /Users/xxxxxx/.phpbrew/build/tmp.1570691957/php-7.1.21
===> Moving /Users/xxxxxx/.phpbrew/build/tmp.1570691957/php-7.1.21 to /Users/xxxxxx/.phpbrew/build/php-7.1.21
===> Checking patches...
Checking patch for replace apache php module name with custom version name
===> Configuring 7.1.21...


Use tail command to see what's going on:
   $ tail -F /Users/xxxxxx/.phpbrew/build/php-7.1.21/build.log


Error: Configure failed:
The last 5 lines in the log file:
checking if the location of ZLIB install directory is defined... no

checking whether to enable bc style precision math functions... yes

checking for BZip2 support... yes

checking for BZip2 in default path... not found

configure: error: Please reinstall the BZip2 distribution

Please checkout the build log file for more details:
	 tail /Users/xxxxxx/.phpbrew/build/php-7.1.21/build.log

話はここから始まる。

bzip2をインストールしてパスを通してみる

下記の記事を参考にしてbzip2をインストールしてみた。

phpbrew installでビルド関係のエラーが出るとき
macでphpbrewを使ってPHP入門

$ brew install libmcrypt bzip2 readline zlib libxml2
$ brew link bzip2 --force

しかし怒られる

Warning: Refusing to link macOS-provided software: zlib
For compilers to find zlib you may need to set:
  export LDFLAGS="-L/usr/local/opt/zlib/lib"
  export CPPFLAGS="-I/usr/local/opt/zlib/include"

For pkg-config to find zlib you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"

Mojaveのせいくさい

同様の現象の記事を発見し、実行してみた。
macOS Mojave で php BZip2 をインストールできない

※”for_macOS_10.14.pkg”の数字の部分は自分のosのバージョンを確認してそれにあった数字に変える必要がある。自分の場合はバージョンが10.14でしたので10.14.pkgにしました。

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /ぱし

パスワードを聞かれるので入力して続ける。

Password:
installer: Package name is macOS_SDK_headers_for_macOS_10.14
installer: Installing at base path /
installer: The install was successful.

うまくいったっぽい。

インストールに再チャレンジ

とりあえずやってみる精神でインストールに再チャレンジ。

$ phpbrew install 7.1.21 +default +mysql

うまくいった!

結論、MacOSがMojaveだったら試してみると良い

見出しで結論を言ってしまったけど、Mojaveだった場合は注意が必要そう。

どうやらMojaveの場合はxcode-selectの最新でmacOS SDK headerがないのが行けないみたいです。

macOS Mojaveでphpenv installを使ってphpが入らない問題について

0