[英]PHP exec command works from terminal but not from web
I created a simple test file lets call it exec.php with this content: 我创建了一个简单的测试文件,并使用以下内容将其称为exec.php:
<?php
exec('scp -r /vhosts/malta/docs/www/mysite/uploads/www.mysite.com/images/promotions/xmas-survey user@255.255.255.255:/vhosts/mysite/docs/www/images/promotions/xmas-survey/',$out);
print_r($out);
?>
Command Executed.
FYI: account user doesn't need a password to access 255.255.255.255 仅供参考:帐户用户不需要密码即可访问255.255.255.255
The problem is here : 问题就在这里:
when I run this file from the terminal like 当我从终端运行该文件时
php /vhosts/test/www/exec.php
the command works but when i try to run it from the web like 该命令有效,但是当我尝试从网络运行它时
http://localhost/test/exec.php
the command doesn't. 该命令没有。
Any ideas? 有任何想法吗?
Thanks in advance 提前致谢
You need to create a ssh login from the webserver to the other server for the user that runs the webserver (eg www-data, apache2, etc...), otherwise the scp command won't work. 您需要为运行网络服务器的用户(例如www-data,apache2等)创建从网络服务器到其他服务器的ssh登录名,否则scp命令将不起作用。
once you create the ssh login the command should work... 创建ssh登录后,该命令应该可以使用...
you might want to secure the ssh login with an rsa key for better security if you haven't done that already 如果您尚未使用rsa密钥保护ssh登录,则可能需要更好的安全性
Probably what's wrong is that you need to specify full path to scp. 可能是错误的,您需要指定scp的完整路径。 Web server user usually doesn't have the same things in path. Web服务器用户通常在路径中没有相同的事物。
To actually diagnoze what went wrong, redirect stderr to somewhere you can read it from. 要实际诊断出问题所在,请将stderr重定向到您可以从中读取的地方。
As example: 例如:
exec($yourcommand . " 2>&1", $out);
// print out the $out variable
检查用户“ www-data”是否具有运行exec.php文件的必要执行权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.