I'm having an issue getting Composer to run on my deployment server through PHP. I have (or will have) a webhook set up with GitHub that will inform me of and accepted pull requests, then auto deploy to the appropriate server.
The issue is coming from the bash line (cd ${localFolder} && composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader)
, it is not giving any errors or output it is as if it was never called. Every other line in the script runs fine, even commands that come after the stubborn one. I have also tried to run the script without any options and with the folder locations hard coded with the exact same results.
When I try and test the command by executing sudo -H -u www-data bash -c 'echo "./download_project.sh 12345678912345 git_branch git_repo'
in the shell it runs fine and to completion.
PHP Code:
$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 Code:
#! /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)
N.B. GUID will be used in the future for archiving purposes.
I would really recommend moving the cd && composer install
out of the subshell you are forcing it into (read: remove the enclosing ()
).
Second, I would temporarily modify the shebang to read #!/bin/bash +x
so you can run the script in a sort of debugging mode.
Then show us the outcome of a run.