2
0

More than 3 years have passed since last update.

某×サーバ宛のdeployerが動かなくなった件

Last updated at Posted at 2020-05-13

事件編

某×サーバへのデプロイ、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をインストールするようにと書き換えることにした。

エピローグ

サーバ選定がアレという件はクライアントにいってください

2
0
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
2
0