Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Apache & VNC - cannot open display: :2.0

Posted on 2008-10-23
4
Medium Priority
?
710 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 2000 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 35

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 35

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 35

Author Closing Comment

by:gr8gonzo
ID: 31509422
Also read my followup
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

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). #…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

972 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