5

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?

Cambiata
  • 3,705
  • 9
  • 35
  • 45

7 Answers7

7

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
  • 124,830
  • 17
  • 198
  • 235
  • 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 Sep 04 '09 at 08:48
  • 1
    This worked perfectly for me, just needed to chown the HOME to apache and done! – Rod Jul 12 '10 at 05:47
1

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
  • 6,793
  • 2
  • 33
  • 36
1

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
  • 11
  • 2
1

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.

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
  • Your solution worked for me (modified for Ubuntu). I'm curious if this opens any security holes should be worried about? – elrobis Mar 22 '18 at 15:52
0

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");
NSSec
  • 4,431
  • 1
  • 27
  • 29
0

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"

0

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