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

后端 未结 7 1299
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 06:55

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 too

相关标签:
7条回答
  • 2020-12-18 07:21

    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.

    0 讨论(0)
  • 2020-12-18 07:23

    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");
    
    0 讨论(0)
  • 2020-12-18 07:31

    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.

    0 讨论(0)
  • 2020-12-18 07:37

    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.

    0 讨论(0)
  • 2020-12-18 07:38

    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

    0 讨论(0)
  • 2020-12-18 07:47

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

    0 讨论(0)
提交回复
热议问题