Php网页找不到bash文件
我是按照这里写的指南做的 我有/var/www/test.phpPhp网页找不到bash文件,php,bash,ubuntu,shell-exec,Php,Bash,Ubuntu,Shell Exec,我是按照这里写的指南做的 我有/var/www/test.php <?php $old_path = getcwd(); chdir('/home/'); $output = shell_exec('./test.sh'); echo "<pre>$output</pre>"; chdir($old_path); ?> 但是在本地运行http://localhost/test.php我得到一张空白页。 我可以从终端运行该文件,我可以以php脚本的形式成功运行
<?php $old_path = getcwd();
chdir('/home/');
$output = shell_exec('./test.sh');
echo "<pre>$output</pre>";
chdir($old_path); ?>
但是在本地运行http://localhost/test.php
我得到一张空白页。
我可以从终端运行该文件,我可以以php脚本的形式成功运行shell_exec('ls'),有人能看到我做错了什么吗?在一些输入错误和权限未设置后,确定问题得到解决,但主要问题似乎是getcwd()没有在本地操作系统或服务器上运行。。。都是Ubuntu 12.04 因此,对于遇到问题的其他人,请务必:
- 检查文件是否可以通过终端执行,如果没有运行
chmod+x/File/location/test.sh
- 接下来使用
echo shell_exec('pwd')检查您所在的目录和移动到的目录。
- 如果不移动目录,请尝试将
替换为getcwd()
dirname(\uuu文件\uu)代码>
`您没有回显$output
回显$output代码>对,继续@ChristopherMorissey,或者直接调用shell_exec,或者输出$output
好,抱歉,这是一个输入错误。。。更新了OP,我仍然有一个空白页:(如果您直接尝试shell_exec命令会发生什么?echo shell_exec('pwd')…可能是文件位置问题
#/bin/bash
mystring="Hello World"
echo "$mystring"