LoginSignup
4
3

More than 5 years have passed since last update.

MacにPHP環境を作成してみる

Last updated at Posted at 2018-03-22

古いMacにphp入れようとしたら、想像より手間がかかったので作業メモ。

前提条件

・OS X 10.10.5 Yosemite

phpenvのインストール

git clone https://github.com/CHH/phpenv.git
cd ./phpenv/bin/
sh phpenv-install.sh 

pathを通す。

~/.bashrc
export PATH="$HOME/.phpenv/bin:$PATH"
eval "$(phpenv init -)"

.bashrcをリロード。

source ~/.bashrc

php-buildのインストール

git clone https://github.com/CHH/php-build.git ~/.phpenv/plugins/php-build

phpのインストール

先にビルドで必要なlibをbrewでインストールしておく。

brew install libevent libjpeg libpng mcrypt libtool openssl autoconf libxml2 lemon re2c

見つからないと怒られる。。。

Warning: Bottle installation failed: building from source.
==> Downloading https://downloads.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz

curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource "libevent"

brewを更新。

brew update && rake

今度は権限周りでエラー。

==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!
Homebrew no longer needs to have ownership of /usr/local. If you wish you can
return /usr/local to its default ownership with:
  sudo chown root:wheel /usr/local
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)

(See full trace by running task with --trace)

権限を変更して再度brewを更新。

再度必要なlibをインストール。

が、またエラー。

Error: openssl 1.0.2e is already installed
To upgrade to 1.0.2n, run `brew upgrade openssl`
Error: Xcode alone is not sufficient on Yosemite.
Install the Command Line Tools:
  xcode-select --install

言われた通り、(OSアップデート後にbrewを使うのに必要らしい。)

xcode-select --install

を実行。インストーラ画面が表示されるので、インストール。

終わったら、今度はopensslをアップデート。

brew upgrade openssl

インストール可能なphpのバージョンを確認。

phpenv install -l

今回は最新の7.2.3をビルド、インストールしてみる。

phpenv install 7.2.3

が、opensslが古いと怒られる。
さっき、アップデートしたのに...

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

Here are the last 10 lines from the log:

-----------------------------------------
configure: WARNING: unrecognized options: --with-mcrypt
configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 2.3, min: 204, excluded: ).
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: OpenSSL version 1.0.1 or greater required.
-----------------------------------------

バージョンを確認してみる。

brew list openssl
/usr/local/Cellar/openssl/1.0.2n/bin/c_rehash
/usr/local/Cellar/openssl/1.0.2n/bin/openssl
/usr/local/Cellar/openssl/1.0.2n/include/openssl/ (75 files)
/usr/local/Cellar/openssl/1.0.2n/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2n/lib/libssl.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2n/lib/engines/ (12 files)
/usr/local/Cellar/openssl/1.0.2n/lib/pkgconfig/ (3 files)
/usr/local/Cellar/openssl/1.0.2n/lib/ (4 other files)
/usr/local/Cellar/openssl/1.0.2n/share/man/ (1680 files)

openssl version
OpenSSL 0.9.8zg 14 July 2015

ん?brewのopensslが使われていない。
先人様のお知恵を拝借

PHP_BUILD_CONFIGURE_OPTS="--with-openssl=$(brew --prefix openssl)" phpenv install 7.2.3

今度はicuがないとのエラー。

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

icuをインストール。

brew install icu4c

再度ビルド、インストール。

ビルドにえらい時間かかったが、無事インストール完了!!

バージョンの確認とか切り替え

インストールされている/使用中のバージョンの確認。

phpenv versions

バージョンの切り替え。

phpenv local XXXX
phpenv global XXXX
4
3
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
4
3