【发布时间】:2020-11-05 22:23:18
【问题描述】:
我想要达到的目标:
每当我将某些内容推送到我的存储库时,我想在我的共享主机上更新我的 git 存储库(其中包含我的 laravel 应用程序)。为此,我在共享主机上有一个 deploy.sh 脚本,它会拉取我的存储库并从我的 laravel 应用程序中删除所有缓存。
为了自动运行这个 bash 脚本,我还得到了一个 php 脚本,每当我将一些东西推送到我的存储库时,它都会由 Github webhook 触发。
我的问题:
我尝试使用我的 php 脚本在我的共享主机上运行我的 bash 脚本,但这不起作用。
我尝试了什么:
当我通过 ssh 在共享主机上手动执行 bash 脚本时,它本身运行得非常好。但它不会被我的 php 文件执行。
PHP
<?php
function debug_to_console($data) {
$output = $data;
if (is_array($output))
$output = implode(',', $output);
echo "<script>console.log('Debug Objects: " . $output . "' );</script>";
}
$access_token = 'maxi9000';
$client_token = $_GET['token'];
if ($client_token !== $access_token)
{
echo 'error 403';
}
else{
$old = getcwd();
echo '</br>'.$old;
$file = $old.'/mhraschan.com/deploy.sh';
echo '</br>'.$file;
if(is_file($file)){
echo '</br>Is file';
if(!is_executable($file)) {
chmod($file, 0755);
echo '</br>file not executable - run chmod';
if(is_executable($file)) echo "File is now executable";
}
//Try to run bash file
$return = shell_exec('bash '. $file);
echo '</br>Shell return: '.$return;
debug_to_console('Shell return'.$return);
}
}
?>
手动运行 php 脚本时浏览器的输出:
/data/web/e115665/html/test
/data/web/e115665/html/test/mhraschan.com/deploy.sh
是文件
文件不可执行 - 运行 chmod
壳返回:
所以我的文件不可执行并运行 chmod 但之后它似乎仍然不可执行,因为它不再运行该行:if(is_executable($file)) echo "File is now executable";
我的 shell_exec 命令也没有任何输出。
有什么办法吗?
【问题讨论】: