I am trying to make a minimal Ubuntu system which only has the software I need. I decided to use Ubuntu server 14.04 for this and install openbox as the GUI. I have also set up nginx to work with php on the system. The main purpose for me to set up the web server was to open GUI applications on my system through the server by pressing a html button.

My goal is to leave a computer attached to the TV and be able to control it using my phone. I felt the easiest way to do that would be to launch the apps I required through the website when I needed as I will be installing a server on the computer anyway

I can confirm that the web server and php works fine. However I am not able to launch the application. I used the following code to get the output when I press the button

     if ($_GET['buton']) {
           echo exec("kodi 2>&1", $output);
           echo $output;
<div id="button"><a href="?kodi=true">kodi</a></button>

The result is

ERROR: Unable to create application. Exiting

Currently I am running this in a virtual machine to make sure everything works before I install this on a physical machine.

I would really appreciate it if someone could help me solve this problem.

  • This sounds a lot like an XY problem. Could you please edit your question and explain what your final objective is? What's the point of launching GUI apps from a web server if they're not going to be displayed to the user who launched them? Your proiblem is that the nginx user doesn't have the right to connect to your regular user's running X session. There are ways around this but there are almost certainly better solutions for whatever your have in mind. – terdon Oct 17 '15 at 12:37
  • @terdon I have updated my answer with the information you asked for – Rumesh Oct 17 '15 at 12:44
  • Ah, I see. Would dedicated apps like this (iOS) or this (Android) that let you use your phone as a mouse/keyboard be a better solution? – terdon Oct 17 '15 at 12:47
  • I had tried hipporemote before but it did not work properly. either way, I was hoping you could help me get it to work using the website as I would be able to customize it to my liking. the dedicated apps are not the preferred solution for me but if I am unable to get a proper answer I guess ill have to use them – Rumesh Oct 17 '15 at 12:51
  • OK, I'll write up an answer but i) this is horribly insecure and ii) are you sure you want this? No offense, but based on the script you show you don't really know much about PHP or HTML. That is riddles with syntax errors. Are thos just copy/paste mistakes or is that the real php you are trying to run? – terdon Oct 17 '15 at 13:15

First of all, don't reinvent the wheel. There are various apps that let your phone act as a wireless keyboard/mouse. For example (these were just the ones I happened to know, there are loads):

You also have things like kodi (previously knokwn as XBMC) to turn your computer into a media center which might do what you need.

If you still prefer to set something up yourself, you will need to allow the nginx user to connect to an existing X session. You will also need to log in once manually (or just set the machine to auto-login to the GUI). You could actually have your server start an X session but it makes more sense to have your user do so so that all your settings etc are there.

  1. Allow other users to connect to your X session.

    You will need to run xhost + to disable access control. The simplest way would be to just add that command to your ~/.profile. Edit ~/.profile and add these lines:

    ## Only run this when logging in graphically
    [ -z "$DISPLAY" ] && xset +
  2. You will need to tell your php app which DISPLAY to connect to. For example:

    if ($_GET['button']) {
      $cmd = "export DISPLAY=:0;  kodi";
    <div id="button"><a href="./a.php?button=1">kodi</a></div>

Note that this is very insecure, use at your own risk.

  • I'm afraid that still does not work properly, I still get the same error – Rumesh Oct 17 '15 at 14:43
  • @Rumesh then we're going to need more details. I tested this on my own machine and it worked fine. If you've just added the line to your ~/.profile, you will also need to log out and back in again. This assumes that i) a regular user has logged in graphically and an X session is running; ii) that xhost + has been run and iii) that the PHP is exporting the DISPLAY. Test it by logging in manually, running xhost + and then using your webpage. – terdon Oct 17 '15 at 14:44
  • It still does not work. I do not have a graphical login interface, I run the command "startx" to run openbox. I also get a new message while logging in now after editing the .profile file. It reads "xset: unable to open display "" " – Rumesh Oct 17 '15 at 15:01
  • @Rumesh yes, it won't work if you don't log in graphically. If you use startx, you should remove the xset command from your ~/.profile and add it at the end of your ~/.xinitrc or ~/.xsessionrc files instead. Also, try logging in normally and running xset + from your openbox session and then using the webpage. Just to confirm that it works and the issue is when the xset + command is run. – terdon Oct 17 '15 at 15:42
  • It still shows the same error after adding xset + to .xinitrc I guess Ill start to look at other alternatives – Rumesh Oct 18 '15 at 5:35

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.