現時点で最高のバージョンマネージャであるところの asdf を使ってPHPのインストールをしたいんですが、思考停止して asdf install php 7.x.xx
みたいにしてもダメなのて手順のメモです。
なお、fish なので、bashやzshの人は適宜読み替えが必要です。
asdf のインストール
Gitで入れる方法もありますが、brewに頼りまくっていきましょう。
上のページに書いてあるままの手順でいれていきます。
$ brew install asdf
$ echo "source "(brew --prefix asdf)"/asdf.fish" >> ~/.config/fish/config.fish
$ brew install \
coreutils automake autoconf openssl \
libyaml readline libxslt libtool unixodbc \
unzip curl
phpのインストールのための設定
asdf-php
https://github.com/asdf-community/asdf-php
上記のプラグインを利用します。
$ asdf plugin add php
READMEを読むと
Prerequirements
Check the .github/workflows/workflow.yml for dependencies, paths, and environment variables needed to install the latest PHP version. To be honest, supporting a major version other than the latest without any extra work from the user is an endless endeavor that won't ever really work too well. It's not that we don't support them at all, but it's almost impossible for us to support them.
的なことが書いてあります。
サラッと書いてあってアレなんですが、GithubActions用の設定ファイルを見て、必要なライブラリは事前にインストールしておけよってことみたいです。
中身を見てみると、stepsにubuntuとmacos用の設定があるので、macos用の設定だけ抜き出すと以下みたいな感じです。
- name: Install packages for macOS
if: matrix.os == 'macos-latest'
run: brew install autoconf automake bison freetype gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libzip pkg-config re2c zlib
- name: Add PKG_CONFIG_PATH environment variable for macOS
if: matrix.os == 'macos-latest'
run: echo "::set-env name=PKG_CONFIG_PATH::$(brew --prefix icu4c)/lib/pkgconfig:$(brew --prefix krb5)/lib/pkgconfig:$(brew --prefix libedit)/lib/pkgconfig:$(brew --prefix libxml2)/lib/pkgconfig:$(brew --prefix openssl)/lib/pkgconfig"
- name: Add bison path for macOS
if: matrix.os == 'macos-latest'
run: echo "::add-path::$(brew --prefix bison)/bin"
brewでの必要なライブラリのインストールと、パスの設定みたいです。
$ brew install autoconf automake bison freetype gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libzip pkg-config re2c zlib
asdfと重複してるのも多々ありますけど、とりあえず気にせずコピってinstallします。
set PKG_CONFIG_PATH /usr/local/opt/icu4c/lib/pkgconfig /usr/local/opt/krb5/lib/pkgconfig /usr/local/opt/libedit/lib/pkgconfig /usr/local/opt/libxml2/lib/pkgconfig /usr/local/opt/openssl@1.1/lib/pkgconfig $PKG_CONFIG_PATH
set PATH /usr/local/opt/bison/bin $PATH
fishの設定に上記を追加します。
workflow.yml
には (brew --prefix libxml2)
みたいな感じで brew
経由でpathを取得する感じになってますが、重いので別途叩いたpathをコピペしてます。
で、ここまできたら完璧!と思いきや、composerのインストールにwgetが必要なので、それも入れておきます。
$ brew install wget
これで準備は完璧!(なはずです)
PHPのインストール
あとは普通にphpをasdf経由でビルドすればいいはずです。
# バージョンは適当に指定してください
$ asdf install php 7.x.x
$ asdf global php 7.x.x
これで完璧です(たぶん)
$ which php
/Users/xxxxx/.asdf/shims/php
$ which composer
/Users/xxxxx/.asdf/shims/composer
追記
- たぶん最新版だとwget要らない気がする
- PHP7.4.4入れたときの設定(fish)
# asdf-php
set -gx PKG_CONFIG_PATH /usr/local/opt/icu4c/lib/pkgconfig /usr/local/opt/krb5/lib/pkgconfig /usr/local/opt/libedit/lib/pkgconfig /usr/local/opt/libxml2/lib/pkgconfig /usr/local/opt/openssl@1.1/lib/pkgconfig $PKG_CONFIG_PATH
set -gx PHP_CONFIGURE_OPTIONS --with-openssl=/usr/local/opt/openssl@1.1 --with-libxml-dir=/usr/local/opt/libxml2 --with-iconv=/usr/local/opt/libiconv --with-zlib