LoginSignup
16
15

More than 5 years have passed since last update.

brew 使っている環境で phpenv, php-buildがコケたメモ

Posted at

phpenv, php-build でコケたのでメモ。

brew で phpenv, php-build をインストールして開発環境を作っていたが、brew update や XCode をアップデートして、Command Line Tools を再度ストールしたら、手元の環境がおかしくなった。

その際に、チェックした項目や、どうやって直したかのメモ。

※各アップデートなど、特に意識せずに連続してやったので、何がどれに影響してたのかの切り分けが出来てない為、もしかしたら間違ってるかもしれません。

とりあえず、手元の環境がおかしくなるまでに行った、影響のあるであろうコマンドなど。

  • brew update && brew upgrade した
  • XCode を5.1にして Command Line Tools をインストールした
  • 間違って、brew install php54-memcached した。
    • このため、php54 もインストールされた
    • 他にも libmemcached, libpng, gettext, unixodbc, とかもインストールやアップデートされた

おそらく、php54-memcached がよろしくなかった。。

※pecl のライブラリは phpize でビルドするが正しい。(はず。)

libpng が 1.6 になってないか?なっていたら、 1.5.x にする

以下のように php-build でビルドがコケた。

$ php-build 5.3.26 ~/.phpenv/versions/5.3.26
# 略
\[Preparing\]: /var/tmp/php-build/source/5.3.26
\[Compiling\]: /var/tmp/php-build/source/5.3.26

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
  "_sk_shift", referenced from:
      _load_all_certs_from_file in openssl.o
  "_sk_value", referenced from:
      _zif_openssl_csr_new in openssl.o
      _zif_openssl_pkcs7_verify in openssl.o
      _php_openssl_parse_config in openssl.o
      _php_openssl_sockop_set_option in xp_ssl.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libs/libphp5.bundle] Error 1
-----------------------------------------

The full Log is available at '/tmp/php-build.5.3.26.20140404214134.log'.
[Warn]: Aborting build.

これはおそらく、 libpng が1.6となっているのが原因。

$ brew info libpng
libpng: stable 1.6.10 (bottled)
http://www.libpng.org/pub/png/libpng.html
/usr/local/Cellar/libpng/1.5.14 (15 files, 1.0M)
  Poured from bottle
/usr/local/Cellar/libpng/1.6.10 (17 files, 1.3M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/libpng.rb
==> Options
--universal
    Build a universal binary

1.6 側に 「*」 となっている。

なので、1.5を使うように変更する。

$ brew switch libpng 1.5.18

これで、再度 $ brew info libpng して、1.5 側に「*」が付いていることを確認。

再度、php-buildして確認する。

php-build でダウンロードに失敗する場合の対処

どうも、ダウンロード先URLが変わっているようで、php-build した時に、「curl: (22) The requested URL returned error: 404」というエラーになる。

php-build コマンドで表示されるURL(下記例なら「 http://php.net/distributions/php-5.3.26.tar.bz2 」)に接続しても、「Unsupported Historical Releases」ページが表示されるだけで、目的のファイルはダウンロードされない。

$ php-build 5.3.26 ~/.phpenv/versions/5.3.26
[Info]: Loaded apc Plugin.
[Info]: Loaded pyrus Plugin.
[Info]: Loaded xdebug Plugin.
[Info]: Loaded xhprof Plugin.
[Info]: php.ini-production gets used as php.ini
[Info]: Building 5.3.26 into /Users/hokutoasari/.phpenv/versions/5.3.26
[Downloading]: http://php.net/distributions/php-5.3.26.tar.bz2

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
curl: (22) The requested URL returned error: 404
-----------------------------------------

The full Log is available at '/tmp/php-build.5.3.26.20140404210408.log'.
[Warn]: Aborting build.

既にダウンロード済みのバージョンで php-build してみると成功した。

どうやら、既にダウンロードしている場合は、ダウンロードプロセスがスキップされる。(当然ですわな。。)

ということで、手動でファイルをダウンロードし、適切な場所に配置することで php-build で「curl: (22) The requested URL returned error: 404」とならないようにする。

お目当てバージョンの tar.bz2 ファイルを http://www.php.net/releases/ 辺りからダウンロードしておく。

※仮に php-5.4.16.tar.bz2 をダウンロードするとする。

ダウンロードしたら、以下のパスに配置する。

/var/tmp/php-build/packages/php-5.4.16.tar.bz2

配置したら、以下のパスの様に、バージョン番号をディレクトリ名として展開しておく。

/var/tmp/php-build/source/5.4.16

これで、$ php-build 5.4.16 ~/.phpenv/5.4.16が通るはず。

16
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15