Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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).
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?
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 :-)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.