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

无人久伴 提交于 2019-12-04 08:38:04

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

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.

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.

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.

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

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"

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

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