Busybox httpd is good for simple static pages, now here is a tutorial for installing lighttpd and php with fastcgi support in the router. Here I choose lighttpd over Apache for its light cpu usage and small memory footprint.
Since all our software are based in /opt folder, some modification must be done to get everything working:
- Install php5 and lighttpd
To install php5 with fastcgi support, run
opkg install libsqlite3
opkg install php5-fastcgi
opkg install php5-modgd
Along with php5, the popular libgd module is also installed. Copy php.ini to its default location.
cp /opt/etc/php.ini /etc/php.ini
After that, test php installation by running:
You should see the version info and no warning/error message.
Install lighttpd and some modules
opkg install lighttpd
opkg install lighttpd-mod-fastcgi
opkg install lighttpd-mod-simple-vhost
- Modify php.ini
Find doc_root = "/www"(or whatever) and change it to doc_root = "/opt/www"
Find extension_dir = "/usr/lib/php" and change it to extension_dir = "/opt/usr/lib/php"
Find ;extension=gd.so and remove the leading semicolon, i.e., change it to extension=gd.so
Find ;date.timezone= , remove the leading semicolon and change it to
date.timezone = "America/New_York"
Replace the red part with yours, a full list is available here.
- Modify lighttpd.conf
With our installation, the configuration file for lighttpd is located at /opt/etc/lighttpd/lighttpd.conf. Edit this file:
First, enable mod_fastcgi and mod_simple_vhost:
find server.document-root and change its value to "/opt/www"
find #server.port = 81 and change it to server.port = 81
This will set lighttpd server to listen port 81. If you want to use port 80, make sure to move the DD-WRT's web admin to another port, details here, step 1.
add following at the end of the file:
fastcgi.server = ( ".php" => ((
"bin-path" => "/opt/usr/bin/php-cgi",
"socket" => "/tmp/php.socket"
- Lighttpd startup script
Create or edit file /opt/etc/init.d/lighttpd with below. Remove any previous contents if its not empty.
[ $# -eq 0 ] && COND="start"
case $COND in
mkdir -p $LOG_D
mkdir -p $RUN_D
$BIN -f /opt/etc/lighttpd/lighttpd.conf -m /opt/usr/lib/lighttpd
Set it as a service
chmod a+x /opt/etc/init.d/lighttpd
ln -s /opt/etc/init.d/lighttpd /opt/etc/init.d/S80lighttpd
- Test lighttpd server
First create the home folder
Then the test file /opt/www/phpinfo.php with contents below:
After that, launch lighttpd
#to stop the lighttpd server, run /opt/etc/init.d/lighttpd stop
Open browser and navigate to http://router_ip:81/phpinfo.php to check the output.