LoginSignup
7
10

More than 5 years have passed since last update.

phpbrewでphpをインストールするときに詰まったこと

Last updated at Posted at 2018-03-25

概要

phpbrewを使ってphpの開発環境を構築する際に、色々詰まってしまったのでメモを残す

手順

1.ミドルウェアのインストール

xcodeインストール

$ xcode-select --install

HomeBrew インストール

# Homebrewのインストール
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

# Homebrewをupdagteして古いバージョンを削除
$ brew update && brew cleanup

PHPBrewインストール

# 依存パッケージのインストール
$ brew install bzip2 curl intltool icu4c libxml2 mcrypt openssl readline zlib
$ brew link bzip2 --force
$ brew link curl --force
$ brew link icu4c --force
$ brew link libxml2 --force
$ brew link mcrypt --force
$ brew link openssl --force
$ brew link zlib --force
opensslのリンク時のエラー
$ brew link openssl --force
Warning: Refusing to link: openssl

Homebrew使い方まとめを見ると、

home brewでopensslをダウンロードしてbrew linkでlinkする方法は2016年8月くらいから使用できなくなった模様。
下記コマンドを実行すると、以下のようなメッセージが出力される

という記載があった....

現在はopensslのlinkは使えないみたいなので、後述するphpのインストール時にopensslはパスを指定しなければいけないみたい

$ phpbrew install 7.1.0 +default +mysql +fpm +openssl +curl +openssl=/usr/local/Cellar/openssl/1.0.2n

1.0.2n の部分はインストールされているOpensslを指定して下さい。

PHPBrew本体をインストール

# インストール
$ curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew

# phpbrewコマンドを使えるように
$ chmod +x phpbrew
$ mv phpbrew /usr/local/bin/phpbrew

# phpbrew初期化
$ phpbrew init

PHP7.1をインストール

$ phpbrew install 7.1.0 +default +mysql +fpm +openssl +curl +openssl=/usr/local/Cellar/openssl/1.0.2n 

依存関係のエラー

上記手順でインストールすると下記のようなエラーが発生した。

===> phpbrew will now build 7.1.0
===> Loading and resolving variants...
Checking distribution checksum...
Checksum mismatch: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 != 68bcfd7deed5b3474d81dec9f74d122058327e2bed0ac25bbc9ec70995228e61
Re-Downloading...
Downloading http://www.php.net/get/php-7.1.0.tar.bz2/from/this/mirror via curl extension

なにやらミスマッチしているみたい...

Checksum mismatch: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 != 68bcfd7deed5b3474d81dec9f74d122058327e2bed0ac25bbc9ec70995228e61

対応策: Homebrewでphpbrewをインストールする。

# 一度phpbrewを削除する
$ rm /usr/local/bin/phpbrew
$ phpbrew cleanup

# homebrew で phpbrew をインストール
$ brew tap homebrew/php
$ brew install phpbrew 

# phpbrew 初期設定
$ phpbrew init

# 一度~/bashrcを読み込んでおく
$ echo '[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc' >> ~/.bashrc
$ source ~/.basrc

インストール時の不具合

phpbrewのこのif文に入ってしまって下記のようなエラーが出力された。

===> phpbrew will now build 7.1.0
===> Loading and resolving variants...
Checking distribution checksum...
Checksum matched: 
===> Extracting /Users/sugitashunsuke/.phpbrew/distfiles/php-7.1.0.tar.bz2 to /Users/sugitashunsuke/.phpbrew/build/tmp.1521871697/php-7.1.0
Error: Unable to find /Users/sugitashunsuke/.phpbrew/build/tmp.1521871697/php-src-php-7.1.0

phpbrew install時に実行されるwww.php.netから圧縮ファイルを~/.phpbrew/distfiles/配下にダウンロードするのが失敗してしまっているみたい。。

対応策: 直接ダウンロード

php-7.1.0.tar.bz2をjp2.php.netのミラーサイトから直接ダウンロード

$ curl http://jp2.php.net/distributions/php-7.1.0.tar.bz2 -o ~/.phpbrew/distfiles/php-7.1.0.tar.bz2
$ phpbrew install 7.1.0 +default +mysql +fpm +openssl +curl +openssl=/usr/local/Cellar/openssl/1.0.2n

無事インストール完了!! 🎉

phpbrew useで使用するphpのバージョンを切り替える

$ phpbrew use php-7.1.0
$ php -v
PHP 7.1.0 (cli) (built: Mar 25 2018 10:37:20) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies

環境構築に1週間以上かけてしまいました.....
何か詰まった時は参考にしてみて下さい:bow:

おわり

7
10
0

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
7
10