简体   繁体   English

PHP exec命令可从终端运行,但不能从网络运行

[英]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.

相关问题 exec命令在终端中工作而不是PHP - exec command works in terminal not with PHP exec命令在php中不起作用,但是在终端/ putty中起作用 - exec command not working in php but works in terminal/putty php exec() 权限 - soffice 命令在终端中有效,但在 php exec() 中无效 - php exec() permissions - soffice command works in terminal but not in php exec() 来自php中Web服务器的exec()命令 - exec() command from web server in php PHP exec()可在命令行中使用,但不能在Web中使用 - PHP exec() works in command line but not in web virtctl 在通过命令行执行而不是从 php exec() 执行时有效 - virtctl works when executed via command line but not from php exec() 命令通过终端正常工作,但不能通过shell_exec php运行 - command works fine through terminal but not shell_exec php 从终端运行shell脚本有效,但从PHP shell_exec运行时不起作用 - Running shell script from terminal works but doesn't work when running from PHP shell_exec 'git pull'命令从终端工作但不是通过git repository hook使用php shell_exec() - 'git pull' command work from terminal but not with php shell_exec() via git repository hook PHP,Memcached可以从命令行运行,但不能从Web运行 - PHP, Memcached works from command line but not from the web
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM