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