Find the answer to your Linux question:
Results 1 to 4 of 4
I'm trying to start vncviewer on raspberry pi using php, where RPi is the client and for my server i'm using Windows OS In php i'm using this script to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2013
    Posts
    2

    starting thightvnc viewer via php


    I'm trying to start vncviewer on raspberry pi using php, where RPi is the client and for my server i'm using Windows OS

    In php i'm using this script to start the vncviewer

    PHP Code:
    $cmd"echo password | vncviewer -autopass " .$ip;
    shell_exec($cmd); 
    It works when I only run the shell script from RPi, but when try it from php i get this error:

    Code:
    Error: Can't open display:
    Is there any workaround for this error ?

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    hello and welcome, pattex007!

    try setting the DISPLAY variable first, e.g.:

    Code:
    export DISPLAY=:0;vncviewer
    the :0 above is my X display number, yours could be different. to get it, open a terminal on the local box (the rasp pi) and do:

    Code:
    echo $DISPLAY
    then use what that command returns as the variable in your export command.

    btw, i assume your PHP script is running on a webpage hosted on the rasp pi, that's the only (easy/non-hackish) way that a local system can launch an executable.

  3. #3
    Just Joined!
    Join Date
    Nov 2013
    Posts
    2
    Quote Originally Posted by atreyu View Post
    hello and welcome, pattex007!

    try setting the DISPLAY variable first, e.g.:

    Code:
    export DISPLAY=:0;vncviewer
    the :0 above is my X display number, yours could be different. to get it, open a terminal on the local box (the rasp pi) and do:

    Code:
    echo $DISPLAY
    then use what that command returns as the variable in your export command.

    btw, i assume your PHP script is running on a webpage hosted on the rasp pi, that's the only (easy/non-hackish) way that a local system can launch an executable.
    thank you for your reply.

    I tried with that export command earlier in a wrong way, but yours is correct and it works in ssh connection!

    in php i got an error something like this:

    Code:
    No protocol specified
    Error: Can't open display: :0.0
    and the problem was simply that I had apparently no access so I ran this:

    Code:
    xhost +
    and now it works !

    thank you

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    great, marking as Solved. Note that you can do this, too, using the Thread Tools link at the top of the page.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •