LoginSignup
0
2

More than 5 years have passed since last update.

現在ログインしているサーバと異なるサーバでcomposer installを実行したい

Posted at

よくデプロイツールなどでは、デプロイ先のサーバーで
composer install を実行してセットアップ処理を行うなどありますが
それを実際にシェルスクリプトでやるとどんな感じになるかというメモです。

実例

ssh越しにコマンドを実行します。
今回は、Composer本体を取得して、そのcomposerを実行します。

実際に実行するシェルスクリプト
DEPLOY_USER="DEPLOYで実行したいユーザー名"
SERVER="DEPLOYするサーバー"
REMOTE_DEPLOY_DIR_PATH="対象サーバのcomposer.jsonがあるディレクトリのフルパス"
ssh $DEPLOY_USER@$SERVER "
curl -sS https://getcomposer.org/installer | php -- --install-dir='$REMOTE_DEPLOY_DIR_PATH' --filename=composer
cd $REMOTE_DEPLOY_DIR_PATH; php composer config -g secure-http false;php composer install
rm $REMOTE_DEPLOY_DIR_PATH/composer
"

余談

最新ソースを取得して、手元で composer install
そのソースを対象サーバに rsync というようなことをやっていたのですが
手元のサーバと、 rsync 先のPHPのバージョンが異なるとできない方法を取っていたので
今回この方法を実践しました。

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