在php中运行bash shell脚本时未创建目录

在php中运行bash shell脚本时未创建目录,php,Php,我想在php中执行bashshell脚本。用于创建目录的shell脚本。但当我在服务器中运行.php文件时,它并没有创建 上面我使用的php代码------- 检查运行它的用户权限。您可以回显“whoami”(bash)命令的输出,以了解使用哪个用户运行脚本 例如,如果它是使用“www data”用户(ubuntu的[可能还有其他]默认的httpd用户)执行的,那么它可能没有在用户的主文件夹中创建目录的权限。我最近发布了一个项目,允许PHP获取一个真实的Bash shell并与之交互(如果请求以

我想在
php
中执行bashshell脚本。用于创建目录的shell脚本。但当我在服务器中运行
.php
文件时,它并没有创建

上面我使用的php代码-------


检查运行它的用户权限。您可以回显“whoami”(bash)命令的输出,以了解使用哪个用户运行脚本


例如,如果它是使用“www data”用户(ubuntu的[可能还有其他]默认的httpd用户)执行的,那么它可能没有在用户的主文件夹中创建目录的权限。

我最近发布了一个项目,允许PHP获取一个真实的Bash shell并与之交互(如果请求以root用户身份),它解决了exec()的限制和shell_exec()。在这里获取:

下载后,您只需使用以下代码:

$shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1  = $shell->exeCmd('cat <<EOF | /home/biswajit/matlab  -nodesktop -nosplash -nodisplay /> /home/biswajit/matlab_result.out');
$return2  = $shell->exeCmd('mkdir -p \'/home/biswajit/Done\'');

//the return will be a string containing the return of the command
echo $return1;
echo $return2;
$shell=\MTS\Factories::getDevices()->getLocalHost()->getShell('bash',true);

$return1=$shell->exeCmd('cat
mkdir('/home/biswajit/Done');
是一个bash命令吗?我想它应该是
mkdir-p/home/biswajit/Done
对不起,但这不是这个matlab命令。是的。那么我可以做什么来运行shell脚本。这里有两个可能性:(安全一个)为该任务专门创建一个目录,并更改组所有权(使用chgrp命令)和权限,以便httpd可以对其进行写入。例如,如果希望脚本能够在/home/biswajit/MatLabOutput中创建文件和目录,则创建一个MatLabOutput,“chgrp www data MatLabOutput”,然后“chmod 770 MatLabOutput”,以便httpd服务用户组可以写入它。(不安全的)使用suEXEC授予用户对httpd服务的权限。
#!/bin/bash

cat <<EOF | /home/biswajit/matlab  -nodesktop -nosplash -nodisplay /> /home/biswajit/matlab_result.out
mkdir('/home/biswajit/Done');
disp('directory created');
exit
EOF
$shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1  = $shell->exeCmd('cat <<EOF | /home/biswajit/matlab  -nodesktop -nosplash -nodisplay /> /home/biswajit/matlab_result.out');
$return2  = $shell->exeCmd('mkdir -p \'/home/biswajit/Done\'');

//the return will be a string containing the return of the command
echo $return1;
echo $return2;