tags:

views:

774

answers:

5

Hi!

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?

A: 

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");
MathieuK
A: 

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.

Mike Buckbee
+3  A: 

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

Martin v. Löwis
Thank you Martin, Mathieu and Mike! Quick prototype: by creating a /var/www/.wine/ directory, and setting it's rights to www-data, it works! I will try your solution, Martin, moving it out of /var/www/
Cambiata
This worked perfectly for me, just needed to chown the HOME to apache and done!
Rodrigo
A: 

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.

Nameless
A: 

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"

Nameless