WDTV Optware tips #4: lighttpd webserver with PHP

As I sat down to start on the wtorrent tutorial I promised back in my rtorrent article I thought about how it is really two seperate parts: getting the webserver running and then getting wtorrent running on that. So today I’ll be going through everything to get the lighttpd webserver running on your Western Digital WDTV, with PHP for dynamic pages too. lighttpd is a lightweight fully featured webserver that suits the WDTV perfect. lighttpd even powers some high profile sites like YouTube and wikipedia.

In order to take advantage of this tutorial you must either be running WDLXTV or Zoranders ext3-boot. You must also have my Optware for WDTV package installed, that stuff is covered elsewhere. I’ll be including every necessary step here, so you might be able to skip around if you already have some of this done.

First ssh/telnet into your WDTV, then update your Optware feed and install lighttpd, php, and php-cgi.

$ ssh root@wdtv-01

BusyBox v1.10.0 (2009-02-15 05:09:42 CST) built-in shell (msh)
Enter 'help' for a list of built-in commands.

# ipkg update
Downloading http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//Packages.gz
Inflating http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//Packages.gz
Updated list of available packages in /opt/lib/ipkg/lists/wdtv
Successfully terminated.
# ipkg install lighttpd php php-fcgi sqlite
Installing lighttpd (1.4.22-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//lighttpd_1.4.22-1_mipsel.ipk
package lighttpd suggests installing e2fsprogs
package lighttpd suggests installing libmemcache
package lighttpd suggests installing lua
package lighttpd suggests installing memcached
package lighttpd suggests installing sqlite
package lighttpd suggests installing mysql
Installing php (5.2.9-3) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//php_5.2.9-3_mipsel.ipk
Installing php-fcgi (5.2.9-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//php-fcgi_5.2.9-1_mipsel.ipk
Installing sqlite (3.6.11-1) to root...
Downloading http://ipkg.nslu2-linux.org/feeds/optware/wdtv/cross/unstable//sqlite_3.6.11-1_mipsel.ipk
Configuring lighttpd
Starting web server: lighttpd
Configuring php
Configuring php-fcgi
Configuring sqlite
Successfully terminated.

Everything installed fine so lets see what comes up in a search for lighttpd in /opt/etc. This directory is where settings and startup scripts for Optware installed programs are.

# find /opt/etc/* | grep lighttpd

Ok, so /opt/etc/init.d/S80lighttpd is the startup script that gets lighttpd going when the WDTV boots up. The really nice file is /opt/etc/lighttpd/conf.d/10-php-fcgi.conf, this file is loaded when lighttpd starts so we don’t have to touch a thing and php works right out of the box. :D

There are two things we’d like two know that the config file will tell, and those are port number and document root directory of the server. Lets grep /opt/etc/lighttpd/lighttpd.conf for those terms.

# cat /opt/etc/lighttpd/lighttpd.conf | egrep \ 'server.port|server.document-root'
server.document-root = "/opt/share/www/"
server.port = 8081

Ok, so /opt/share/www/ is where all of our html/php/etc files will go. Lets test it out and see if php is really enabled. We’ll do this by editing index.php in our web root, index.php is the default file returned by lighttpd. I’ll use nano to edit /opt/share/www/index.php and add the following:


// Show all information, defaults to INFO_ALL


// Show just the module information
// phpinfo(8); yields identical results.



The above is a good test page (directly from php.net) because it displays all the different parameters that php was compiled with and accessible modules. If you created the webpage you can navigate to it now in your favourite browser. Don’t forget to enter the port number, which is 8081 if you didn’t change the config file above. The address will look like this, just change the wdtv-01 to whatever your wdtv’s ip address is.


I’ll however just download the page from the webserver, dump its contents to standard out, and grep a few key terms to make sure everythings working correctly.

# wget -O - wdtv-01:8081 2> /dev/null | egrep 'Server API|System'
<tr> System </td><td class="v">Linux wdtv-01 2.6.15-TvDock #2 PREEMPT Mon Sep 15 20:20:41 CST 2008 mips </td></tr>
<tr><td class="e">Server API </td><td class="v">CGI/FastCGI </td></tr>

it works, cool! Now your WDTV is ready to serve up any php pages you give it. That was almost too easy.

Just to review now:

  • the webserver is started when you turn your WDTV on

  • the root directory of the webserver is /opt/share/www
  • /opt/etc/init.d/S80lighttpd is the startup script, it can be used in three ways:
    • to restart: /opt/etc/init.d/S80lighttpd restart

    • to start: /opt/etc/init.d/S80lighttpd start
    • to stop: /opt/etc/init.d/S80lighttpd stop

    Ok, so next time will actually be the wtorrent tutorial...

March 29th, 2009 16:32

You could also use disc0′a webserver.app.bin. I have tested it and it works great with WDLXTV. I also did it the hardway before realizing there was a webserver app.bin available. Might save you a little time.

<<< edit: Good point. Downside to his webserver though is the fairly limited expandability of it, but it is quite good for those lookin for a shortcut. –b-rad >>>

April 3rd, 2009 04:05

Followed your tutorial and it worked without a problem on your WDlxTV 0.4

Thanks mate! :)

[...] writeup presumes that you have already executed the steps from part 1 and part 2. If you haven’t done them yet, then get over and complete them [...]

May 16th, 2009 12:01

I like the idea of having such low cost webserver for free, but running it as root ?
Can’t I run lighttpd under a different user with
less priviledges ?
Maybe the answer is obvious, but I don’t Linux well
tx for all you for us !

July 9th, 2009 06:36

I don’t understand this… who do you type it in?

# wget -O – wdtv-01:8081 2> /dev/null | egrep ‘Server API|System’
System Linux wdtv-01 2.6.15-TvDock #2 PREEMPT Mon Sep 15 20:20:41 CST 2008 mips
Server API CGI/FastCGI

July 9th, 2009 06:36

sorry, how do you type it in?

November 25th, 2009 18:22

Many thanks for this lighttpd setup.
I have obtain an error when starting server in error.log
“(server.c.1105) fdevent_init failed ”
after short googling i have fix it by make change in the config file /opt/etc/lighttpd/lighttpd.conf

server.event-handler = “poll”

February 11th, 2010 17:22

what is the login pass for that webserver???

<<< edit: Whatever you set it to…? –b-rad >>>

September 16th, 2010 07:51

Works perfectly, though I had one issue, namely I got lines like these:
fdevent_linux_sysepoll.c.131: epoll_create failed (Function not implemented), try to set server.event-handler = “poll” or “select”

The solution was to uncomment the line server.event-handler in lighttp.conf and set it to “poll”, and then restart the server. Works without a hitch now!

September 16th, 2010 13:37

Oh wow. I didn’t realize that this was already posted :P

Anyway, if anyone would like to help me, I get errors like these in error.log http://pastebin.com/9Fhh2HQb

The PHP’s I tried with is a SQL Lite manager http://www.sqlitemanager.org/

phpinfo(); runs without a problem, so it’s working good otherwise.

September 16th, 2010 13:38

When I get those errors I see “500 – Internal Server Error” in the web browser. Sorry for the triple post.