事件編
某×サーバへのデプロイ、deploy:vendorsタスクでエラる
エラー概要(意訳 このエラーはパッケージがPHP7.2を要求しているがオメーのPHP環境5.4だぜ!出直してこい!)
Loading composer repositories with package information
Installing dependencies from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Dependency resolution completed in 0.000 seconds
Your requirements could not be resolved to an installable set of packages.
Problem 1
- This package requires php ^7.2 but your PHP version (5.4.16) does not satisfy that requirement.
この前まではできていたはず。
なぜか急にできなくなった。
サーバのコンパネ上の設定ではPHP7.3を使う設定になっている。
これに関してはHTTPサーバの設定なのでCLIのPHPバージョンはデフォの5.4というのがよくある症状なのは知っていたし
set('bin/php', function () {
return '/usr/bin/php7.3';
});
という感じで指定のPHPを使うように設定していた。
この設定を入れるとphp コマンドを /usr/bin/php7.3 と置き換えてくれる。
いままではこれで問題が発生しなかった。
調査編
/usr/bin/composer install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-sug
gest
失敗したコマンドをよく見る
あれれー?おかしいぞー?
/usr/bin/composer
どうやらサーバー側のcomposerを使用しているようである。
おそらくこのcomposerのshebangがデフォルトのphpを指しているのであろう。
このせいで5.4のphpと認識されているようである。
解決編
deployerはリモートにcomposerがインストールされていれば
そのcomposerを自動的に使う。
入っていない場合はcomposer.pharをインストールしてつかう。
どうやれば強制的にcomposer.pharを使わせられるか謎だったので
ソースを見ることとする
https://github.com/deployphp/deployer/blob/master/recipe/common.php#L117
ここだ。
set('bin/composer', 'なにがし')
で上書きすることが可能そうだ。
私はめんどくさかったので
set('bin/composer', function () {
run("cd {{release_path}} && curl -sS https://getcomposer.org/installer | {{bin/php}}");
$composer = '{{bin/php}} {{release_path}}/composer.phar';
return $composer;
});
こんな感じで常にcomposerをインストールするようにと書き換えることにした。
エピローグ
サーバ選定がアレという件はクライアントにいってください