This question already has an answer here:

I have the following script (alert.sh) which has been setuid'd:

DISPLAY=:0.0 notify-send --urgency=low -i python "The job has finished"

and the following PHP file alert.php:

echo exec("/path/to/alert.sh")

When I su to www-data and run php alert.php, I get an alert on my screen. All good.

However, when I open alert.php in the browser, nothing happens.

I suspect some environment variable needs to be set, but I'm not sure which.

marked as duplicate by Gilles, slm, jasonwryan, Chris Down, Anthon Dec 30 '13 at 5:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Just figured it out while digging through the environment variables, I also have to set $XAUTHORITY to whatever the variable is in the normal login.

XAUTHORITY=/home/myusername/.Xauthority DISPLAY=:0.0 notify-send --urgency=low -i python "The job has finished"

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