ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
into my php script, it works fine. However, if I put
Code:
$r = exec('myX11application');
echo $r;
it doesn't (to be precise, the script still works, but myX11application is not executed). Of course, scripts are run by user "apache", who doesn't have access to X11 server and doesn't even have DISPLAY variable defined.
I installed virtual framebuffer Xvfb, created a small bash script:
Code:
Xvfb :2
export DISPLAY=:2
myX11application
and called it with exec from php, but it still doesn't run since it looks like Xvfb can't start if the normal X server is running (I need that for development purposes). The reported error from Xvfb is
Code:
(EE) config/hal: NewInputDeviceRequest failed (2)
Is there a solution to have php running your X11 applications with normal X server running?
This way, apache can have permission to run the script at the same time as myX11application has permission to access the X server of another user. You do this by setting the other user as owner of the file, then chmod 4755 scriptfile. If it doesn't work, try to do the same with a compiled program instead of a shell script; refer to http://www.tuxation.com/setuid-on-shell-scripts.html for how to do this.
Solution #2:
Instead of Xvfb, try Xvnc. It can run at the same time as your X server. You can run it as apache user, so apache will have no problems displaying X applications on that buffer. To view the applications started by apache, just start vncviewer from your X server and connect to Xvnc. This connection is only password authenticated, so it doesn't matter what user is connecting with vncviewer. Note however that the VNC protocol isn't necessarily safe, so be sure to use it locally only and configure your firewall appropriately.
This way, apache can have permission to run the script at the same time as myX11application has permission to access the X server of another user. You do this by setting the other user as owner of the file, then chmod 4755 scriptfile. If it doesn't work, try to do the same with a compiled program instead of a shell script; refer to http://www.tuxation.com/setuid-on-shell-scripts.html for how to do this.
Solution #2:
Instead of Xvfb, try Xvnc. It can run at the same time as your X server. You can run it as apache user, so apache will have no problems displaying X applications on that buffer. To view the applications started by apache, just start vncviewer from your X server and connect to Xvnc. This connection is only password authenticated, so it doesn't matter what user is connecting with vncviewer. Note however that the VNC protocol isn't necessarily safe, so be sure to use it locally only and configure your firewall appropriately.
Thanks for your input, but unfortunately both methods failed.
#1: I followed also the advice on the link you provided, creating a C program, which sets UID and runs the script, but when it comes to executing myX11application, it still reports:
Code:
No protocol specified
myX11application: cannot connect to X server :0
#2: I tried Xvnc and vncserver, but it is almost the same thing:
Code:
New 'X' desktop is myServerURL:2
Starting applications specified in /var/www/.vnc/xstartup
Log file is /var/www/.vnc/myServerURL:2.log
No protocol specified
myX11application: cannot connect to X server :2
Oops, just a few moments after I posted my complaints, solution #2 started to work. Not sure why, I guess I only changed screen from :2 to :1 and vncserver back to Xvnc.
Many thanks for this, I hope 40 virgins will wait for you when your time to join the heaven comes...
Oh, now I get it. Thanks for your help, this solution worked fine. I had a few issues with the application crashing, but it was because it tried to write a log and it couldn't because it had no permissions, but I solved that as well, so everything works fine now. Many thanks again.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.