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
Updated list of available packages in /opt/lib/ipkg/lists/wdtv
# ipkg install lighttpd php php-fcgi sqlite
Installing lighttpd (1.4.22-1) to root...
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...
Installing php-fcgi (5.2.9-1) to root...
Installing sqlite (3.6.11-1) to root...
Starting web server: lighttpd
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.
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'
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...