LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-08-2005, 02:48 PM   #1
hsingams
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Rep: Reputation: 0
Error: Can't open display (X-windows & apache)


I've a linux machine (Redhat - KDE3) that I usually connect to using VNC.
Example, I telnet to the machine first and run a script with following commands to open a display on hostname:45.
1. Xvnc -rfbauth /home/myusername/.vnc/passwd :45
2. setenv DISPLAY hostname:45
3. startkde&
Later I open the display using a VNC client and can work on the remote desktop.

My problem is, I want to use this (or any) display when I run an application
(as user "apache") from a webpage. For example - I have an application,
say K2, that needs a display to run (because it opens a window to draw stuff etc.).
If I invoke K2 from a webpage I get a message in apache error log - "Error: can't open a display".
I use a PHP script to run system commands (invoke K2 application) on host.

After doing a thorough google search, I found that, X doesn't allow access to a display unless the user (who is trying to access) has 1) a valid .Xauthority OR 2) X server listening to TCP connections. Since user "apache" has no valid .Xauthority I tried to find "-nolisten tcp" in the KDE config files to comment it out. But I couldn't find a file with that option listed. When I run a "ps -auxw | grep X" command on the host, I see only the Xvnc process (which I ran before to open a display), i mean, I don't see any X process running with -nolisten tcp option.

I did a "xhost +localhost" while logged into the machine with "myuserid" and later set the environment variable "DISPLAY hostname:45" in the PHP script I use to open the application (as user "apache"). But it doesn't seem to work.

In summary, how do I make a display available to the apache user when
running an application from webpage? i.e., how to fix the "Error: can't open a display" problem?


I appreciate your help.
Thanks,
Hemanth
 
Old 08-08-2005, 03:13 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Try setting display in the script to JUST ":45". If you set it to hostname:45, it will be seen as a remote connection. (This all, of course, requires the xhost bit as well).
 
Old 08-08-2005, 04:28 PM   #3
hsingams
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks David! But I still get the same error.
Anyother suggestions, pls?

- Hemanth
 
Old 08-08-2005, 04:33 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Hrrm, hard to say. How are you setting the DISPLAY variable? How are you executing your program? Have you tried something simple like running an xterm?
 
Old 08-08-2005, 05:33 PM   #5
hsingams
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for pointing it out. Apparently, I didn't set the DISPLAY variable right.
I used PHP "exec('export DISPLAY=hostname:45')" before.
Now I changed it "putenv(DISPLAY=:45)" and it worked :-)

- Hemanth
 
Old 08-08-2005, 09:34 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Yeah, the exec launches a subprocess... so it can't change the env vars of the PHP process. Glad you got it working.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Can't open display" error when try to use a program remote heande Linux - Newbie 2 03-11-2005 11:13 AM
Error: can't open display gopalkasat Linux - Networking 8 12-13-2004 02:59 PM
Suse 9.1 Error: Can't open display dan7 General 5 07-23-2004 11:59 AM
wdb Error: Can't open display: 172.16.1.28:0 murugesan Linux - Networking 4 02-19-2004 05:01 AM
Could not open display error reyemarr Linux - General 14 12-06-2003 11:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration