为什么不能从PHP Web浏览器中执行命令? [英] Why cannot PHP execute a command from web browser?
问题描述
这是非常简单的,但我不能让它在所有的工作。花了很多时间和我总是放弃。我创建的PHP脚本称为copy.php,它应该调用一个python脚本调用copy.py.
This is really simple but I cannot get it to work at all. Spent many hours and I've always give up. I created php script called copy.php and it should call a python script called copy.py.
我要执行这样的命令行
<?php exec('/var/www/html/copy.py'); ?>
真的很简单。
为什么我不能得到从PHP的exec执行python脚本()? Python脚本里面的功能是从一个不同的目录中的error_log副本(外的Apache)到html目录。
Why cannot I get the python script executed from php exec()? The function inside python script is to get a copy of error_log from a different directory (outside of Apache) into html directory.
如果我运行从终端
> php copy.php
它确实执行功能和制作的拷贝。这是为什么Web浏览器是不是这样做呢?
It did execute the function and made a copy. Why is that the web browser isn't doing it?
让我简化:
为什么不能执行exec(CP /无功/日志/的httpd / error_log中的/ var / www / html等/路径/要/ PHP /脚本)工作?
why cannot exec("cp /var/log/httpd/error_log /var/www/html/path/to/php/script") work?
它工作正常,如果我在终端上键入它,但不能在浏览器中运行的时候。
it works fine if I type it in terminal but not when run in a browser.
推荐答案
它不工作的唯一原因是因为你没有设置写权限!
The only reason its not working is because you didn't set the write permissions!
执行
sudo nano /etc/sudoers
然后把以下内容:
And then put the following:
www-data ALL=(root) NOPASSWD:ALL
这篇关于为什么不能从PHP Web浏览器中执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!