[英]Running a node file, via a .sh from .php on linux
I'm trying to run a node file from php. 我正在尝试从php运行节点文件。 The following works...
以下作品...
running the node from terminal running an .sh that runs the node file from terminal running a .sh from php, that writes a text file ( so the php is succesfully triggering the .sh ) 从运行.sh的终端运行节点,从运行php的.sh终端运行节点文件,写入文本文件(因此php成功触发了.sh)
However, when I run the .sh file, running the node file from php it fails. 但是,当我运行.sh文件时,从php运行节点文件失败。 I have tried using wait 30 ( the process takes about 10 seconds ) to make sure it's not exiting before completion.
我尝试使用等待30(该过程大约需要10秒钟)来确保它在完成之前没有退出。 Do I need to set any special permissions in order for php --> .sh --> node to work?
我是否需要设置任何特殊权限才能使php-> .sh->节点正常工作? Done quite a bit of searching can't find anything.
完成大量搜索后找不到任何东西。
It's important to understand how the file and execution chain is completed in order to understand why this won't work (assumedly). 重要的是要了解文件和执行链是如何完成的,以了解为什么它不起作用(假定)。
Assuming a pretty common setup below... 假设下面有一个非常普通的设置...
When Apache is initialized, it has an owner, we'll say www-data
in this particular case. 初始化Apache后,它就有一个所有者,在这种情况下,我们将称
www-data
。 Now, Apache will execute and listen on port 80 as the www-data
user. 现在,Apache将以
www-data
用户身份执行并侦听端口80。 This means that all requests it handles from here on out will be executed as the www-data
user. 这意味着它从现在开始处理的所有请求都将以
www-data
用户身份执行。
So when you go to http://example.com/my-page.php , Apache is going to receive this request. 因此,当您访问http://example.com/my-page.php时 ,Apache将收到此请求。 Then it's going to go out and find the file associated with
my-page.php
in the file system based on it's DocumentRoot
in the VirtualHost
directive. 然后它将出去,并根据
VirtualHost
指令中的DocumentRoot
在文件系统中找到与my-page.php
关联的文件。 Once it's done this, the PHP interpreter that has been attached to the .php
file will do a top down interpretation of the file. 完成此操作后,已附加到
.php
文件的PHP解释器将对该文件进行自顶向下的解释。
Once it gets to your bash script, www-data
is still the owner. 一旦进入您的bash脚本,
www-data
仍然是所有者。 Now the bash script
has been executed as www-data
in this case, and I'm willing to bet that www-data
(or your Apache user) is not in the list of sudoers (and rightfully so). 现在,在这种情况下,
bash script
已作为www-data
执行,我敢打赌, www-data
(或您的Apache用户)不在sudoers列表中(理应如此)。
To combat this problem, you should instead make sure that the node
instance can be invoked without sudo permissions on your paritcular configuration. 为了解决此问题,您应该确保在实例配置上可以在没有sudo权限的情况下调用
node
实例。 If this is just a localhost thing and the outside world isn't going to be hitting it, I'd say adding www-data
(or your Apache user) to the list of sudoers wouldn't be a bad thing. 如果这只是本地主机的事情,而外界不会遇到麻烦,我想说将
www-data
(或您的Apache用户)添加到sudoers列表中并不是一件坏事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.