如何从php网页执行程序? [英] How to execute a program from a php web page?
问题描述
我在安装了某些程序的Linux机器上运行apache.我想从php页面调用该程序并获取输出.
I have apache running on a Linux machine where a certain program is installed. I want to call the program from a php page and get the output.
程序需要运行某些环境变量,例如LD_LIBRARY_PATH,带有库的路径以及其他变量.在不是 apache 用户的计算机上为用户 X 定义了环境.
The program needs certain environment variables to run, e.g. LD_LIBRARY_PATH with path to libraries plus extra variables. The environment is defined for a user X on the machine that is not the apache user.
到目前为止,我已经想到了以下选项(并不意味着它们都很聪明或安全):
So far I have thought of the following options (not meaning that they are all smart or safe):
- 允许用户 apache 以用户 X 的身份运行程序(以允许拥有完整环境的方式).食谱 ?
- 修改用户 apache 的环境.我不知道怎么回事,因为apache是 nologin 用户.
- 以具有适当环境的用户身份SSH到另一台计算机.这意味着Web服务器与本机之间没有密码(公用/专用密钥)连接.危险吗 ?
- Allow user apache to run the program as user X (in a way that allows having the full environment). Recipe ?
- Modify the environment of user apache. I don't see how because apache is a nologin user.
- SSH to another machine as a user that has the proper environment. It means to have a no password (public/private keys) connection between the web server and this machine. Is it dangerous ?
问题
- 我是否忽略了一个更简单或更佳的选择?
- 您将使用什么选项?为什么?
- Did I overlook a simpler or better option ?
- What option would you use and why ?
Questions
推荐答案
您对此平台有完全控制权吗?
Do you have full control over this platform?
您可以查看 suexec 或您可以在虚拟主机中配置以上内容,并将运行身份作为用户或组设置为有权访问您的二进制文件的用户.
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.
在当前设置中,您可以创建一个新组,将apache用户/组分配给所述组,将组应用于您要执行的具有读/写或读/执行权限的二进制文件,并让美好时光角色
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.
这篇关于如何从php网页执行程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!