Solved

Apache & VNC - cannot open display: :2.0

Posted on 2008-10-23
4
674 Views
Last Modified: 2012-06-21
I have a CentOS 5 server running Apache and vncserver. I also have a 3rd-party utility that works with vncserver to take a screenshot of the current desktop / display. We rebooted the server recently and everything came up just fine but when Apache tries to run the 3rd-party utility to take the screenshot, the utility says it "cannot open display: :2.0"

If I SSH into the server and run the utility directly on the command line as root, the utility works perfectly. Apache has all the correct permissions to execute the utility. I've restarted vncserver but that doesn't change anything. I think it's just some issue of Apache having access to the display, but I'm not sure where to go from there. Any help would be appreciated. Thank you!

0
Comment
Question by:gr8gonzo
  • 3
4 Comments
 
LVL 23

Accepted Solution

by:
Mysidia earned 500 total points
ID: 22793357
It may have access to the display,  but could be the case that the proper environment variables are not set,  for accessing the VNC desktop.

Normally, there are two environment variables you need set to access a display in common setups.. the first is the identity of the display.

The second is the path to the X user  'authorization'  file   that contains the secret cookie of the user's desktop.

In the shell you would type
export DISPLAY=:0
export XAUTHORITY=/home/user/.Xauthority


In other contexts, the variables need to be set before running the utility


In Apache httpd you can normally  use  mod_env
to change environment variables,  within a virtual host or  <Location>,
for example:

SetEnv DISPLAY :0
SetEnv XAUTHORITY /home/apache/.Xauthority



Or use


PassEnv DISPLAY
PassEnv XAUTHORITY


And set the environment variables accordingly   when starting  Apache httpd.
0
 
LVL 34

Author Comment

by:gr8gonzo
ID: 22813262
That might be it. After trying a few other things, I restarted Apache and it came right up. The environment variables might make sense, since I restarted it from the shell, while it initially started up as a standard service, so it wouldn't have inherited any of my environment.

I will try to break it again and then set those environment variables in Apache and see if that does the trick.
0
 
LVL 34

Author Comment

by:gr8gonzo
ID: 23003445
So it looks like that wasn't a complete solution but what I -WAS- able to do was to enable access for localhost and 127.0.0.1 (the quick fix was to just enable all hosts) using xhost. After defining the DISPLAY environment variable, type:

xhost +

...to disable the control access. If that works for you (reader), then put back control access and then use xhost to add only the IP addresses/hosts that are being blocked. The changes are temporary until the next reboot, but you can save a file into /etc/ to save those settings. Read the xhost man page for details.
0
 
LVL 34

Author Closing Comment

by:gr8gonzo
ID: 31509422
Also read my followup
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now