Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/');

My hostname is steven-Z-CLASS

Here is my shell script:

export DISPLAY=steven-Z-CLASS:0.0
wmctrl -m

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


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?

share|improve this question

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.

share|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

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:

export DISPLAY=:0.0
wmctrl -m
share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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