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. :-(


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

1 Answer 1


It seems that you're running your script as root. If that is the case, then the problem is clear: chromium will not run as root. You need to pick a different user for this task.

Next question is, does PHP have access to the X server? Running xauth list instead of the browser (and checking its output) will probably shed some light on the matter. This answer explains how to share X server cookies between users.

  • As I noted in my post, I have tried without the sudo and so tried launching with www-data as the user. Then under EDIT, I noted that I also tried with su -c <script> pi to launch as pi.
    – Chiwda
    Commented Sep 5, 2023 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.