简体   繁体   English

exec / system()-脚本被调用直到从PHP调用为止

[英]exec/system() - script being called works until called from PHP

I have a bash script: 我有一个bash脚本:

run.sh 运行

#!/bin/sh
cd /var/www/project/bin/ 
CMD="./executable <full_path_to_file>;
$CMD

When I run this program from the terminal. 当我从终端运行该程序时。 (ie ./run.sh , it works fine) (即./run.sh ,它可以正常工作)

However when I call it from PHP: 但是,当我从PHP调用它时:

system("full_path_to_sh_file", $out);

It calls the script successfully, and even runs the executable, but now the executable throws an error saying that the supplied file can't be found. 它成功调用了脚本,甚至运行了可执行文件,但是现在可执行文件抛出错误,提示找不到所提供的文件。

Any ideas? 有任何想法吗?

  1. How do you run PHP script, from webserver or command line? 如何从Web服务器或命令行运行PHP脚本?
  2. If from webserver, what user is it run (httpd or apache?) 如果从Web服务器运行,则运行什么用户(httpd或apache?)
  3. Make sure the environment as same as when you are running from terminal (for example: same user) 确保环境与从终端运行时的环境相同(例如:同一用户)
  4. Try this if running as different user: sudo -u apache /fullpath/run.sh 如果以其他用户身份运行,请尝试以下操作: sudo -u apache /fullpath/run.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM