部署者:'composer install' - 找不到命令

问题描述

我正在使用 deployer 在服务器上打包一个 symfony 应用程序。在部署期间,我还需要运行 composer install 来运行 bin/console 等重要命令。只有这样才能完成部署。不幸的是,部署失败并在“composer install”中中断并显示错误消息:

[Deployer\Exception\RuntimeException (127)]
The command "cd /usr/home/xxx/public_html/sw6-staging/releases/1.1 && composer install" Failed.
Exit Code: 127 (Command not found)
================
bash: line 1: composer: command not found

这是deploy.PHP中的任务:

task('sw:deploy',function(){
run('cd {{release_path}} && composer install');
});

task('deploy',[
'deploy:prepare','deploy:lock','deploy:release','deploy:update_code','sw:deploy',])->desc('Deploy your project');

但是如果我通过 CLI 直接在服务器上运行命令“composer install”,它会运行。是什么问题,我该如何解决

部署器版本 6.8。 PHP 7.2 版

非常感谢

解决方法

我遇到了完全相同的问题。似乎 deployer 使用非登录、非交互式 shell 连接到服务器,它不会加载像 ~/.bash_profile -> ~/.bash_login -> {{1 这样的 shell 启动文件}}。

就我而言,~/.profile 具有以下条目:

.bashrc

但是无论是 PATH="$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$PATH" 还是 nodenpm 都可以到达,所以显然没有使用这个文件。也没有 composer 所以我创建了一个并在那里添加了路径:

~/.bash_profile

然后我在调用 echo "PATH="$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$PATH" > ~/.bash_profile 之前使用 source 命令加载 ~/.bash_profile

composer install
,

在 6.8 中,您可以 use shellCommand option 拥有一个“登录 shell”(并加载 shell 启动文件):

host('example.com')
    ->shellCommand('bash -ls')
example.com:
  shellCommand : bash -ls