Solved

Apache & VNC - cannot open display: :2.0

Posted on 2008-10-23
4
684 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

808 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