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

本秂侑毒 提交于 2019-12-06 02:35:10

问题


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"

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

exec("wine tool.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

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


回答1:


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"))




回答2:


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

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




回答3:


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 :(

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.

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.

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

In my PHP script I have something like this:

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

Seems to work so far.




回答4:


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

# 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:1 before starting Wine from my web script.




回答5:


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

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:

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



回答6:


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.

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

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

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




回答7:


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

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



来源:https://stackoverflow.com/questions/1377388/how-to-use-wine-from-apache-php-var-www-is-not-owned-by-you

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!