[英]How to execute a program from a php web page?
I have apache running on a Linux machine where a certain program is installed. 我在安装了某些程序的Linux机器上运行apache。 I want to call the program from a php page and get the output.
我想从php页面调用该程序并获取输出。
The program needs certain environment variables to run, eg LD_LIBRARY_PATH with path to libraries plus extra variables. 该程序需要某些环境变量才能运行,例如LD_LIBRARY_PATH以及库路径以及其他变量。 The environment is defined for a user X on the machine that is not the apache user.
在不是apache用户的计算机上为用户X定义了环境。
So far I have thought of the following options (not meaning that they are all smart or safe): 到目前为止,我已经想到了以下选项(并不意味着它们都很聪明或安全):
if you know the (values of) environment variables you need to set, you could simply prepend them to your exec 如果您知道需要设置的环境变量(的值),则只需将它们放在执行程序之前
exec('LD_LIBRARY_PATH="/you/paths"; OTHER_VAR="baz"; /your/bin');
that will execute /your/bin
with the given ENV variables set, but as the apache user, not user X . 将使用给定的ENV变量集执行
/your/bin
,但作为apache用户,而不是用户X。 If the program needs to run as a specific user, SSH doesn't seem like such a bad idea. 如果程序需要以特定用户身份运行,SSH似乎不是一个坏主意。
Do you have full control over this platform? 您对此平台有完全控制权吗?
You can look into suexec , or mpm-iTK 您可以查看suexec或mpm-iTK
You could configure the above within a virtual host, and set the run as user or group to that which has access to your binary. 您可以在虚拟主机中配置上述内容,然后将运行身份作为用户或组设置为有权访问二进制文件的用户或组。
In your current setup, you could create a new group, assign the apache user/group to said group, apply group to the binary you want to execute with read/write or read/execute permissions, and let the good times role. 在当前设置中,您可以创建一个新组,将apache用户/组分配给所述组,将组应用于要执行的具有读/写或读/执行权限的二进制文件,并让其成为美好时光。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.