Installing PHP on the Yun

Something that appears obvious to everyone except me is..

How EXACTLY do you edit uHTTPd config file, as per instructions below.

The aim is to get PHP5 running so php web pages can be used to drive browser based user interface.

I have a simple php file sitting in www folder on sd card, and I have installed PHP5 and -cgi using opkg, and they show as installed, however php page doesnt open as a parsed php page in a browser, but rather tries to download.

Given all this has been done via YunSerialTerminal, and it isnt exactly a text editor, what tool or method does one use to actually edit the config files. Is it edited in place, or does one have to somehow obtain the contents of "/etc/config/uhttpd", edit, and somehow load back onto Yun ?

Any help much appreciated.

A minimal php5 installation includes


In /etc/php.ini ensure that the doc_root is empty if you are using multiple uhttpd instances (each on its own port). This enables the uhttpd 'home' variable to work for you.

Ensure that you uncomment the extension interpreter line for PHP in the main section of the uHTTPd config file:
list interpreter ".php=/usr/bin/php-cgi"

A common, simple text editor for Linux is "nano"; check if it is installed. E.g. "nano /path/to/configuration.conf" to edit a file.

For general use, once you have an IP on the Yun I would expect you would use an SSH client to connect instead of a serial terminal. For Windows you should go download "PuTTY".


All works !

I had never realised that an SSH client was anymore than a serial terminal. I used TeraTerm When you run Nano and the window transforms to a text editor, memories of msdos flooded back.

For anyone else trying the steps to getting php5 running are:

  1. Get Yun logged onto your wifi network so it has internet connection
  2. Use SSH client to log into Yun, using user: root, password: arduino
  3. Type

opkg update
opkg install php5 php5-cgi
opkg install nano

nano /etc/config/uhttpd

  1. The text editor will open and scroll down until you find the line…

list interpreter “.php=/usr/bin/php-cgi”

  1. Delete the #, and press o to save file.

  2. restart the Yun, and PHP should work.

I have tested on a few basic PHP commands and it works perfectly.
Given PHP is a very powerful and easy to use language, it should allow one to write complex software that sits on the Sd card and takes up none of the Yun memory. Next step is to present sensor data stored on sd card in google graph format.

Thanks for help.

To get date and time function working in PHP need…

opkg update
opkg install zoneinfo-core zoneinfo-europe

Also, you can call PHP functions from the Arduino by using HttpClient:

sensorinfo = “&temp1=23&temp2=44”;

sensorinfo = “http://localhost/sd/myprogramname/savelog.php?” + sensorinfo;

Savelog.php is a php page that saves sensor data to the SD card (removing the need for any file system acces on the Arduino (saving space). Save the php page in the program folder /www and it will be loaded to sd card automatically when you upload Arduino program over WiFi. (Provided you have created a folder on sd card called “arduino/www”)

<?php date_default_timezone_set('Europe/London'); $DateNow = date("Y-m-d H:i:s"); $outtext = "&time=" . $DateNow . "&" . $_SERVER['QUERY_STRING']; $dfile = "../log.txt"; $file = fopen($dfile,"a"); $f = fputs($file,$outtext); fclose($file); echo "Logged..." . $outtext; ?>