0

I use exec() command in php to run linux command.

My command is like this, using wine.

$cmd = '/usr/local/bin/wine C://metaeditor.exe /compile:"C://MQL4/Experts/mytest.mq4" /log > execerror.log';
set_time_limit(500);
exec($cmd,$out,$ret);

var_dump($ret);

This script works on CLI but not work on Apache Server.

(If exec() success it makes file.)

$ret returns int(1)

and execerror.log is blank.

I made sure that PHP version is the same and apache user and CLI user is the same(username app).

I don't have any clue yet, Where should I check??


I found the log in apache error log.

wine: '/root' is not owned by you, refusing to create a configuration directory there

So somehow wine from exec() requests the access in /root/.wine folder.

However I use app user to run apache and there is the /home/app/.wine folder.

Why it requires to access /root folder?? I want to use /home/app/.wine directory.

[app@jp1 httpd]$ ps aux | egrep '(apache|httpd)'
root      9701  0.0  1.2 577180 23952 ?        Ss   Aug06   6:54 /usr/sbin/httpd -k start
app      31883  0.1  2.4 580504 47132 ?        S    19:53   0:00 /usr/sbin/httpd -k start
app      31884  0.2  2.7 582564 52188 ?        S    19:53   0:01 /usr/sbin/httpd -k start
app      31885  0.3  2.7 598212 52988 ?        S    19:53   0:01 /usr/sbin/httpd -k start
app      31886  0.0  0.7 577180 13492 ?        S    19:53   0:00 /usr/sbin/httpd -k start
app      31887  0.0  1.7 580112 33772 ?        S    19:53   0:00 /usr/sbin/httpd -k start
app      31888  0.1  2.2 584208 43064 ?        S    19:53   0:00 /usr/sbin/httpd -k start
app      31889  0.1  2.4 596272 47664 ?        S    19:53   0:00 /usr/sbin/httpd -k start
app      31890  0.2  2.2 599560 43668 ?        S    19:53   0:01 /usr/sbin/httpd -k start

Solution

I use sudo -u command and solved.

exec("sudo -u app /usr/local/bin/wine ~~");

whitebear
  • 11,200
  • 24
  • 114
  • 237
  • As usual in Linux, this comes down to permissions & environment in which a command is run. Try running this command as the `www-data` user in the CLI instead to see the culprit. – Mike Doe Nov 10 '19 at 10:28
  • `1` means `EPERM` (Operation not permitted). User accounts / environment and accessibility of X11 might be relevant for `wine` executables. `2>&1` for capturing stderr. See also [How can I debug exec() problems?](//stackoverflow.com/q/12199353) – mario Nov 10 '19 at 10:29
  • @emix my server works with `User app Group apache` and CLI user is `app`. – whitebear Nov 10 '19 at 10:42
  • @emix and my `/var/www/html/myproject` folder is belonging to app / app – whitebear Nov 10 '19 at 10:43
  • @mario Thank you it is great hint, so it is related with permission after all as everybody told me. – whitebear Nov 10 '19 at 10:44
  • I found out this line in apache log `wine: '/root' is not owned by you, refusing to create a configuration directory there` may be this is the great hint – whitebear Nov 10 '19 at 10:48
  • THank you verymuch, I almost there and updated the article. – whitebear Nov 10 '19 at 11:08
  • Answer your question then and post the solution. Mark it as "solved" tomorrow. – Mike Doe Nov 10 '19 at 11:15
  • Thank you emix. I still struggling final inch. – whitebear Nov 10 '19 at 11:17

0 Answers0