I'm running xubuntu 11.10. From php, I'm calling a shell that exports the display and then calls wmctrl. Every time I call wmctrl, I see an error "Cannot open display".

I call my shell from php:

$output = shell_exec('/var/www/wmctrl.sh');

My hostname is steven-Z-CLASS

Here is my shell script:

#!/bin/bash
export DISPLAY=steven-Z-CLASS:0.0
echo $DISPLAY
wmctrl -m

When I run this, I see the echoed display value in my php page:

steven-Z-CLASS:0.0

However, wmctl does not run. I see this error in the apache log:

Cannot open display.

Any ideas why wmctrl can't open the display?

link|improve this question

57% accept rate
feedback

2 Answers

On the steven-Z-CLASS system you'll need to run xhost +OTHERNAME where "OTHERNAME" is the name of the system that is running the "wmctrl -m" command.

The xhost command allows the user to modify the security on the local X11 server to allow "OTHERNAME" to connect and display graphics on it.

link|improve this answer
Thanks very much for your help. I'm running everything on the same machine. I found that if I run this command in a shell sudo xhost + before I load the php page, everything works! – Sparky1 Nov 8 '11 at 23:13
feedback

DISPLAY=steven-Z-CLASS:0.0 means:

  • screen 0 (after the dot)
  • on X server 0 (between : and dot)
  • on host steven-Z-CLASS

Try removing steven-Z-CLASS if the machine running the PHP command is the same machine as the X server one:

#!/bin/bash
export DISPLAY=:0.0
echo $DISPLAY
wmctrl -m
link|improve this answer
Thanks for the suggestion. Tried it but no luck. sudo xhost + is getting me there though. – Sparky1 Nov 8 '11 at 23:16
feedback

Your Answer

 
or
required, but never shown

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