【发布时间】:2020-12-03 23:17:22
【问题描述】:
这是代码,它的目的是运行一个 bash 脚本。 (index.php)
<html>
<title>
hello
</title>
<b>hello</b>
<body>
<?php
exec('bash /var/www/html/test.sh');
?>
</body>
</html>
什么时候做 php index.php 它会执行 test.sh 但是当我用浏览器运行它时它不会运行 bash 脚本。
考虑 index.php 在 test.sh 的同一目录下 我已经完成了 chmod 和 chown。
这是 test.sh
#!/bin/bash
python3 /var/www/html/test.py
这是 test.py
import logging
a = "Hello world "
LOG_FILENAME = '/var/www/html/test.txt'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug(a)
【问题讨论】:
-
test.sh 有什么作用?你怎么确定它没有被执行?剧本应该有答案吗?因为您没有回显也没有保存结果。有任何错误信息吗?
-
不能在浏览器中直接运行php。必须有一个服务器来解析 php
-
这很可能是没有“bash test.sh”的完整路径的问题
-
@AmbrishPathak 我有一个网络服务器,我在 /var/www/html/index.php 中使用它
-
@DefinitelynotRafal 主要目的是运行一些 python 应用程序,但 shell 只是在执行它们。其中之一是一个hello word python,它可以登录test.txt,然后我跟踪那个txt文件。当我在终端中运行 index.php 时,它会写入日志,但是当我使用 www.example.com/index.php 执行它时,它会显示“hello”但没有登录 test.txt