我在部署服务器上通过PHP运行Composer时遇到了问题。我已经设定(或将要设定)与GitHub的webhook,以通知我并接受拉取请求,然后自动部署到适当的服务器。
问题出现在bash行
当我尝试执行
PHP代码:
注意:GUID将来会用于归档目的。
问题出现在bash行
(cd $ {localFolder} && composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader)
中,它没有给出任何错误或输出,就好像从未调用过一样。脚本中的每一行都可以正常运行,即使是在该顽固命令之后运行的命令也是如此。我还尝试过不带任何选项运行脚本,并使用精确相同的结果硬编码文件夹位置。当我尝试执行
sudo -H -u www-data bash -c 'echo "./download_project.sh 12345678912345 git_branch git_repo'
以测试命令时,它可以正常运行并完成。PHP代码:
$data = json_decode(utf8_encode(file_get_contents("data.json")));
$command = "/var/www/download_project.sh" . " " . uniqid() . " " . $data->deployTable[$deploy]->branch . " " . $data->deployTable[$deploy]->repository;
echo ($command . "</br>");
echo shell_exec($command);
Bash代码:
#! /bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: $(basename $0) [guid] [branch] [repository]"
exit 1
fi
working="/var/www/"
guid=$1
branch=$2
repository=$3
localFolder="${working}temp/"
localFile="${working}temp.zip"
#clone the appropriate branch and repository to the /var/www/temp folder
#result: functions as expected
git clone -b $branch git@github.com:ORGANIZATION/$repository.git $localFolder
#moves the sql folder out of /var/www/temp and onto /var/www to be used for db creation and/or migration
#result: functions as expected
mv "${localFolder}sql" "${working}sql"
#removes /var/www/temp/doc as it is not needed or wanted for production
#result: functions as expected
rm -rf "${localFolder}doc"
#downloads all dependencies into the /var/www/temp/vedor folder
#result: nothing happens
(cd ${localFolder} && composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader)
注意:GUID将来会用于归档目的。