On a Raspberry Pi 3B+ (using stretch), I have a bash script that looks like this.
pkill chromium-browse
chromium-browser --noerrdialogs --disable-infobars --kiosk https://www.example.com --incognito
The bash script works fine when it is run at the command prompt. I am executing it in php like this:
@exec("sudo bash /var/www/local.example.com/restartbrowser.sh", $output, $resultCode);
The script executes and the first line (pkill) executes. However, the second line does not. I get the following from $output:
[0]=> string(197) " --disable-quic --enable-tcp-fast-open --disable-gpu-compositing --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-args=enable_stagevideo_auto=0 --ppapi-flash-version=" [1]=> string(151) "[3448:3448:0902/120435.075925:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180."
and $resultCode is 1
I have also tried executing the script without the sudo and the $output is:
array(1) { [0]=> string(197) " --disable-quic --enable-tcp-fast-open --disable-gpu-compositing --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-args=enable_stagevideo_auto=0 --ppapi-flash-version=" }
but no browser is launched.
Note that the line that starts the browser is exactly the same in my autostart file - i.e. ~/.config/lxsession/LXDE-pi/autostart and it works fine there.
I have also tried adding 2>&1 to the end of the command but that doesn't appear to do anything. The permissions on all files in that directory are:
-rwxr-x--- 1 pi www-data
What could be the problem? Any suggestions to troubleshoot and/or fix the problem will be greatly appreciated.
EDIT: I also tried the following line in the php file:
@exec("su -c '/var/www/pb.podrones.com/restartbrowser.sh' pi", $output, $resultCode);
to no avail. :-(
CLARIFICATION
I neglected to mention the obvious - that I have the following to enable execution of programs by www-data (using sudo visudo to add the below line)
www-data ALL=NOPASSWD: ALL