Solved

Apache & VNC - cannot open display: :2.0

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access_log 17 100
video edge NVR Device Discovery Problem 4 34
networking details on centos 6.6 4 52
How to update  and reset admin password for Linux 5 45
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

867 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

15 Experts available now in Live!

Get 1:1 Help Now