Run Wine via PHP

Questions about Wine on Linux
Locked
Kartoffel
Newbie
Newbie
Posts: 2
Joined: Sun Jan 24, 2016 4:29 am

Run Wine via PHP

Post by Kartoffel »

Hello,

My Apache2 needs to run a Windows file which works perfectly under command line.

It is a simple C++ debug code that does the following:

Code: Select all

#include <iostream>
#include <fstream>
#include <unistd.h>

int main(int argc, char *argv[])
{
  std::ofstream file("FILE_TO_WRITE");
  file << "Hello World" << std::endl;
  file.close();

  std::cout << "STARTING" << std::endl;
  /*
  for (int i = 0; i < 5000; i++)
  {
    std::cout << i << std::endl;
    usleep(900000);
  }*/
  std::cout << "ENDING" << std::endl;

  return 0;
} 
I have compiled this file in two version, under the Linux, called the file 'main' and on Windows, called the file 'main.exe'. Imported them both on the server.

To trigger them, I use the following PHP script:

Code: Select all

<?php
exec("./main 2>&1", $output, $return_var);
var_dump($output);
echo "\nReturnVar: $return_var";
?>
Doing it on 'main' works as expected, generate a file called 'FILE_TO_WRITE' and outputs on the PHP script:
array(2) { [0]=> string(8) "STARTING" [1]=> string(6) "ENDING" } ReturnVar: 0
However, running the PHP script with 'wine main.exe' throws back:
array(0) { } ReturnVar: 159
Although, both commands work perfectly from command line (to note doing './main.exe' works perfectly).

My question is: how come Apache struggles to start my Windows file and how would I be able to have it start it ?

UPDATE: After looking in Apache error logs, here is what I have when executing the Windows file:
sh: line 1: 10677 Bad system call ./main.exe 2>&1
Thanks for your help !
Kartoffel
Newbie
Newbie
Posts: 2
Joined: Sun Jan 24, 2016 4:29 am

Re: Run Wine via PHP

Post by Kartoffel »

Ah, topic just got approved.
There are further advancements in the issue:

On Apache, I am using the module apache2-mpm-itk which allows to run virtual hosts under different users.
The problem is this module once enabled (even if the virtual host doesn't use its commands), will prevent the execution of my Windos files for some reason.

However, when it'd disabled, I'll be able to start it as expected.
Do anyone have an idea ? Or is there some other module that'd be able to run virtual hosts with different users (privileges separation) ?

Thanks !
User avatar
dimesio
Moderator
Moderator
Posts: 13208
Joined: Tue Mar 25, 2008 10:30 pm

Re: Run Wine via PHP

Post by dimesio »

Kartoffel wrote: Do anyone have an idea ? Or is there some other module that'd be able to run virtual hosts with different users (privileges separation) ?
This isn't a Wine question. You really should ask this on an Apache forum.
Locked