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-01BusyBox 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
/opt/etc/init.d/S80lighttpd
/opt/etc/lighttpd
/opt/etc/lighttpd/lighttpd.conf
/opt/etc/lighttpd/conf.d
/opt/etc/lighttpd/conf.d/01-default.conf
/opt/etc/lighttpd/conf.d/10-php-fcgi.conf
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.
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:
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
// Show just the module information.
// phpinfo(8); yields identical results.
phpinfo(INFO_MODULES);
?>
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.
http://wdtv-01:8081/
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...
Takenover83March 29th, 2009 16:32You 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 >>>
SteveApril 3rd, 2009 04:05Followed your tutorial and it worked without a problem on your WDlxTV 0.4
Thanks mate!
April 9th, 2009 01:58[...] 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 [...]
MarkMay 16th, 2009 12:01I 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 !Frosty_CROJuly 9th, 2009 06:36I 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/FastCGIFrosty_CROJuly 9th, 2009 06:36sorry, how do you type it in?
valdorNovember 25th, 2009 18:22Many 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.confserver.event-handler = “poll”
sadfcAWefbFebruary 11th, 2010 17:22what is the login pass for that webserver???
<<< edit: Whatever you set it to…? –b-rad >>>