I have Apache and PHP running on my local Linux desktop. My PHP script launches "xcalc", and looks like this:
<?php
shell_exec("xcalc");
?>
When I execute the PHP script using the PHP binary, I see xcalc running on the desktop. When I execute the same script through Apache, I see nothing happening on the screen. I can't figure out where it fails.
I changed Apache's User and Group to a regular user, just to make sure that all X settings are correct.
xcalc needs either a -display
option or the DISPLAY
environment variable set to know which X server to display on. When you run it from the shell, it's probably picking up $DISPLAY
from your shell environment, but the Apache web server normally won't have that
set.
You may also run into X authentication issues, if the X session isn't being run by the same user as the Apache web server, since X normally relies on a shared secret (the “magic cookie”) stored in the $HOME/.xauthority
file of the user who logged into the X session.