如何从 Apache/Php 使用 Wine?- '/var/www' 不属于你

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1377388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:08:01  来源:igfitidea点击:

How to use Wine from Apache/Php? - '/var/www' is not owned by you

phpapachewine

提问by Cambiata

I need to run a windows command line tool from a php script on my Debian server. For that, I'm trying Wine. Invoking wine and the tool via terminal works fine: "$ wine tool.exe"

我需要从 Debian 服务器上的 php 脚本运行 Windows 命令行工具。为此,我正在尝试 Wine。通过终端调用 wine 和该工具工作正常:“$ wine tool.exe”

But when running the same from my php script...

但是当从我的 php 脚本运行相同的...

exec("wine tool.exe");

exec("葡萄酒工具.exe");

...I get the following in my Apache error log: wine: '/var/www' is not owned by you, refusing to create a configuration directory there

...我在我的 Apache 错误日志中得到以下信息:wine: '/var/www' is not allowed to create a configuration directory there

I guess this is a simple fundamental linux user rights problem... Should I change the user rights for Wine to www-data? How?

我想这是一个简单的基本 linux 用户权限问题......我应该将 Wine 的用户权限更改为 www-data 吗?如何?

回答by Martin v. L?wis

You should create a separate home directory for running Wine. Create a directory which is owned by www-data, set the HOME variable, su www-data, and run winecfg once; then run tool.exe (as that user). In the exec call, make sure that HOME is set (try exec("HOME=/tmp/wine wine tool.exe"))

您应该为运行 Wine 创建一个单独的主目录。创建一个属于www-data的目录,设置HOME变量,su www-data,运行winecfg一次;然后运行 ​​tool.exe(作为该用户)。在 exec 调用中,确保设置了 HOME(尝试exec("HOME=/tmp/wine wine tool.exe")

回答by Nameless

Since I'm running FreeBSD I get the error wine: '/root' is not owned by you. Creating a folder called '/var/www' won't be of much help :(

因为我运行的是 FreeBSD,所以我收到错误 wine: '/root' is not allowed by you。创建一个名为“/var/www”的文件夹不会有太大帮助:(

Apache is running as www, or the threads are, while the main process starts as root as far as I know. If you don't have any admin rights, you can always try to ask the admin to add a line in the sudoers file.

Apache 以 www 或线程的身份运行,而据我所知,主进程以 root 身份启动。如果您没有任何管理员权限,您可以随时尝试要求管理员在 sudoers 文件中添加一行。

I've added the following line to my sudoers file and it let's Apache (the www user) use sudo to run wine as my user (myuser), instead of as www or root.

我已将以下行添加到我的 sudoers 文件中,它让 Apache(www 用户)使用 sudo 作为我的用户(myuser)而不是 www 或 root 运行 wine。

www localhost = (myuser) NOPASSWD: /usr/home/myuser/bin/wine

www localhost = (myuser) NOPASSWD: /usr/home/myuser/bin/wine

In my PHP script I have something like this:

在我的 PHP 脚本中,我有这样的东西:

exec("HOME=/usr/home/myuser sudo -u myuser /usr/home/myuser/bin/wine /usr/home/myuser/test.exe"

exec("HOME=/usr/home/myuser sudo -u myuser /usr/home/myuser/bin/wine /usr/home/myuser/test.exe"

Seems to work so far.

到目前为止似乎工作。

回答by Alexander Farber

I'm using CentOS 5.5 Linux (same as RHEL) and have just copied the .winedirectory from my home and changed the owner recursively:

我正在使用 CentOS 5.5 Linux(与 RHEL 相同)并且刚刚从我家复制了.wine目录并递归地更改了所有者:

# sudo cp -R ~/.wine /var/www
# sudo chown -R apache.apache /var/www/.wine

BTW for some trickier Windows program I had to install Xvfb(rpm package name: xorg-x11-server-Xvfb) and run it from inside of /etc/inittab at :1 and then set DISPLAY to localhost:1before starting Wine from my web script.

顺便说一句,对于一些棘手的 Windows 程序,我必须安装Xvfb(rpm 包名称:xorg-x11-server-Xvfb)并从 /etc/inittab 中的 :1 运行它,然后localhost:1在从我的 Web 脚本启动 Wine 之前将 DISPLAY 设置为。

回答by Mike Buckbee

You're going to want to use chownto modify the ownership of wine and tool.exe.

您将要使用chown来修改 wine 和 tool.exe 的所有权。

Be advised that this could potentially open up some security concerns.

请注意,这可能会引发一些安全问题。

回答by Raja Chakraborty

SOLVED So Finally, used 'mono' command and run through PHP script. Here is my command:

SOLVED 所以最后,使用'mono'命令并通过PHP脚本运行。这是我的命令:

shell_exec('mono Release/X12Parser.exe Release/EDI_FILES/first_edi.edi Release/XML_FILES/firstXML.xml');

To Install mono please follow this link. Install mono

要安装单声道,请点击此链接。 安装单声道

Thanks

谢谢

Raja Chakraborty

拉贾·查克拉博蒂

回答by Nameless

Or... you could skip the whole sudo thing. Start wine to generate a config file in your home directory, then ask the admin to do a chown www:users .wine on your wine config files.

或者......你可以跳过整个 sudo 事情。启动 wine 在你的主目录中生成一个配置文件,然后让管理员在你的 wine 配置文件上做一个 chown www:users .wine 。

Apache should now have the needed rights to run wine using your config file.

Apache 现在应该拥有使用您的配置文件运行 wine 所需的权限。

The www user seems to have another name on linux...

www 用户在 linux 上似乎有另一个名字......

exec("HOME=/usr/home/myuser /usr/home/myuser/bin/wine /usr/home/myuser/test.exe"

exec("HOME=/usr/home/myuser /usr/home/myuser/bin/wine /usr/home/myuser/test.exe"

回答by NSSec

Seems harmless, as long as wine can function without configuration directory.

似乎无害,只要 wine 可以在没有配置目录的情况下运行。

Try and find out if wine can run with a specified configuration directory on the commandline. If not there's two things you can do: either you copy an existing (from your user for instance) wine config directory into /var/www or you just ignore this warning and redirect STDERR output somewhere else:

尝试找出 wine 是否可以在命令行上使用指定的配置目录运行。如果没有,您可以做两件事:要么将现有的(例如来自您的用户)wine 配置目录复制到 /var/www 中,要么忽略此警告并将 STDERR 输出重定向到其他地方:

exec ("wine tool.exe 2>/dev/null");