What's new

[TUTORIAL] LIGHTTPD web server with PHP support through Entware

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

TeHashX

Very Senior Member
New site with updated guide

Works only on Merlin's firmware because /jffs partititon is required for Entware environment
We need a usb-flash formatted EXT2 or a usb-hdd formated EXT3, may not work on FAT32 or NTFS.
First, setup Entware from this guide (see youtube video here)

Login to router with putty terminal and enter this commands:
# opkg install lighttpd
# opkg install php5-cgi
# opkg install lighttpd-mod-fastcgi
# /opt/etc/init.d/S80lighttpd stop
# opkg install wget
# rm /opt/etc/lighttpd/lighttpd.conf
# /opt/bin/wget -c -O /opt/etc/lighttpd/lighttpd.conf http://tinyurl.com/amvkxt3 --no-check-certificate
# /opt/bin/wget -c -O /opt/share/www/index.html http://tinyurl.com/bxfxpq6 --no-check-certificate
# /opt/bin/wget -c -O /opt/share/www/test.php http://tinyurl.com/b9b34kp --no-check-certificate
# /opt/etc/init.d/S80lighttpd start

Go to 192.168.1.1:81 and if you see this page, the lighttpd web server is configured correctly

rm5it1.png


Go to 192.168.1.1:81/test.php and if you see this page, the php-mod-fastcgi is configured correctly

i5usfo.png


TO ACCESS THE WEBSITE FROM WAN
--------------------------------------------------------------------------
# opkg install nano
# nano /jffs/scripts/firewall-start
and add this lines
#!/bin/sh
iptables -I INPUT -p tcp --destination-port 81 -j ACCEPT
Save with CTRL-O / Enter / and exit with CTRL-X
# chmod a+rx /jffs/scripts/firewall-start
Go to Port Forwarding and redirect port 80 to 81, after reboot you should have access from wan.


Video HERE...
 
Last edited:
I'm facing a little problem here, after rebooting the router, S80lighttpd it's starting normally with all other apps in init.d folder (it's running in background) but I can't access the web site from lan or wan, if I restart with /opt/etc/init.d/S80lighttpd restart command, initiating to work fine, dunno why.
Solved temporary by adding this lines to /jffs/scripts/services-start
#!/bin/sh
sleep 20
/opt/etc/init.d/rc.unslung start
sleep 10
/opt/etc/init.d/S80lighttpd restart

Anyone else is facing the same problem?
 
I'm facing a little problem here, after rebooting the router, S80lighttpd it's starting normally with all other apps in init.d folder (it's running in background) but I can't access the web site from lan or wan, if I restart with /opt/etc/init.d/S80lighttpd restart command, initiating to work fine, dunno why.
Solved temporary by adding this lines to /jffs/scripts/services-start
[/COLOR][/COLOR]
Anyone else is facing the same problem?

I had some similar issues with Entware and Minidlna (I was merely testing something). Seems to be a timing issue if starting some services too early through services-start, inserting a sleep command also resolved my issue.
 
I had some similar issues

TeHashX, RMerlin, can the /usr/sbin/httpd be a cause?
Think I'm not faced this trouble because I'm manually «move» httpd from TCP80 port with my own scripts:
$ cat /opt/etc/init.d/S00firmware_services
#!/bin/sh

prefix="/opt"
PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin

start() {
...
# Moving web interface to another port.
# You'll need it while using your own web-server on 80 port
/usr/bin/killall httpd
cd /www
/usr/sbin/httpd -p 65080 &
...
}
...
 
TeHashX, RMerlin, can the /usr/sbin/httpd be a cause?
Think I'm not faced this trouble because I'm manually «move» httpd from TCP80 port with my own scripts:

The issue I encountered was with Minidlna (the Entware version), so I doubt it was related to httpd in any way. I was just testing service auto-starting through unslung at the time.
 
Hello TeHashX!
Thanks for your nice how-to!
Do you think it's possible to install lighttpd on optware as well? I'm not ready yet for entware and would like to use this nice webserver which I know reasonable well from NSLU2...

jmir (RT-N16 user)
 
Last edited:
Lighttpd is available on optware too, but probably you should make some minor changes to it
# ipkg install lighttpd
There is Cherokee Web Server tutorial that you may try, look at my signature.
 
Last edited:
Hi!

Can you guys recommend a good lighttpd forum where I can post questions on lighttpd configuration issues? :)
 
I can't seem to get this to work - any ideas? Lightttpd wont start
"/opt/etc/init.d/S80lighttpd start" Just fails. Tried redoing the whole thing over 3 times now.

And it seems dropbox defaults to HTTPS now - which wget doesn't seem to like, so I had to transfer the files manually.

On a RT-N66u with 374.43
 
Last edited:
I can't seem to get this to work - any ideas? Lightttpd wont start
"/opt/etc/init.d/S80lighttpd start" Just fails. Tried starting over 3 times now.
Please run lighttpd -f /opt/etc/lighttpd/lighttpd.conf too see whats wrong.

And it seems dropbox defaults to HTTPS now - which wget doesn't seem to like, so I had to transfer the files manually.
Busybox's wget doesn't support https, but you may use wget from Entware.
 
Please run lighttpd -f /opt/etc/lighttpd/lighttpd.conf too see whats wrong.

Code:
2014-07-01 20:05:57: (configfile.c.898) source: /opt/etc/lighttpd/lighttpd.conf line: 2 pos: 1 invalid character in variable name
2014-07-01 20:05:57: (configfile.c.954) configfile parser failed at: (EOL)

Busybox's wget doesn't support https, but you may use wget from Entware.
Ohh thanks for the info - I'll grab Entwares wget

EDIT: Thanks for that debug command, figured out dropbox is messing with the file when saving it, so copied the text into the lighttpd.conf file manually and it works without a hitch. Thanks for your help, much appreciated.

Downloaded wget through Entware but the wget command still seems to call Busybox's wget. How do I call the wget from entware?
 
Last edited:
Downloaded wget through Entware but the wget command still seems to call Busybox's wget. How do I call the wget from entware?
If you don't want to re-login, use full path to wget binary, like /opt/bin/wget https://some.path
Let me explain what happened. When you typed wget …, the busybox shell start finding wget binary on some folders (see $PATH variable) and remember what has been found. Thats why new wget binary will not be used while you not re-logged via telnet/ssh.
 
I recall there is a command called rehash that will "reindex" what's in the path? But it's probably not available in busybox.
 
I'm having problems starting the Lighttpd service...

Administrator@RT-AC66U:/tmp/home/root# /opt/etc/init.d/S80lighttpd start
Starting lighttpd... failed.
Administrator@RT-AC66U:/tmp/home/root# lighttpd -f /opt/etc/lighttpd/lighttpd.co
nf
2014-10-12 20:03:56: (configfile.c.901) source: /opt/etc/lighttpd/lighttpd.conf line: 1 pos: 5 invalid character in variable name
2014-10-12 20:03:56: (configfile.c.957) configfile parser failed at:

Please help me to find out what's going on here. Bit of a novice when it comes to these things. I'm running Merlin's latest firmware.
 
Thanks for replying.

Here it is...

Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    	<meta http-equiv="cache-control" content="max-age=0" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="-1" />
		<meta http-equiv="pragma" content="no-cache" />
        <meta http-equiv="refresh" content="1; url=http://dl.dropbox.com/u/47669650/RT-N66U/lighttpd/lighttpd.conf">
        <script type="text/javascript">
            Date.now = Date.now || function() { return +new Date; };
            var tt=Date.now();
            var ot,rt,lt,bt,et,dt,bkt,ast,tut,bct,aft;
            var tte=0,rte=0,lte=0,bte=0,ete=0,dte=0,bkte=0,aste=0,tute=0,bcte=0,afte=0;
            var t=new Image();

                        
            function ex() {
             u="http://dl.dropbox.com/u/47669650/RT-N66U/lighttpd/lighttpd.conf";
             var xl = document.createElement("script");
             xl.src ="http://loadus.exelator.com/load/?p=360&j=d&g=002&id=43edd9c7cde94e56a81fc3d4&turl="+encodeURIComponent(u);
             xl.type = "text/javascript";xl.async = true;
             if(xl.addEventListener){xl.onload=function(){ete=Date.now()-et;}} 
             else if(xl.readyState){xl.onreadystatechange=function(){if(xl.readyState=='loaded'){ete=Date.now()-et;}}}
             et=Date.now();document.body.appendChild(xl);}

            function af() {var afp=new Image();afp.onload=function(){afte=Date.now()-aft;};aft=Date.now();
            afp.src='http://go.affec.tv/map/tu/43edd9c7cde94e56a81fc3d4';}

            function bc() {var bcp=new Image();bcp.onload=function(){bcte=Date.now()-bct;};bct=Date.now();
            bcp.src='http://clients.bluecava.com/data/pixel.png?p=793c6424-37d3-4d65-bfb4-4f60a0ddae5e&peer39=13193%2C13176%2C13174%2C13194%2C13189%2C13177%2C13175%2C13053&rn=43edd9c7cde94e56a81fc3d4411068316'+tt;}
			
            function tstu(){tute=Date.now()-tut;}
            function tu() {var tp=new Image();tp.onload=tstu;tp.onerror=tstu;tut=Date.now();
            tp.src='http://d.turn.com/r/dd/id/L2NzaWQvMS9jaWQvMjU3MTk5MzYvdC8w/dpuid/43edd9c7cde94e56a81fc3d4';}
            
                        function bk() {var frm=document.createElement('iframe'); 
             frm.src='javascript:void(0)';frm.width='0';frm.height='0';frm.frameBorder='0';frm.name='__bkframe';
             document.body.appendChild(frm);
             var b=document.createElement("script");
             b.src="http://tags.bkrtx.com/js/bk-coretag.js";b.type="text/javascript";
             if(b.addEventListener){b.onload=function(){bkex();bkte=Date.now()-bkt;}} 
             else if(b.readyState){b.onreadystatechange=function(){if(b.readyState=='loaded'){bkex();bkte=Date.now()-bkt;}}}
             bkt=Date.now();document.body.appendChild(b);}
            function bkex() {var b = document.createElement("script");b.type = "text/javascript";document.body.appendChild(b);
             var t = document.createTextNode('bk_addPageCtx("URL","http://dl.dropbox.com/u/47669650/RT-N66U/lighttpd/lighttpd.conf");bk_doJSTag(12997,6);');b.appendChild(t);}
                        
            function map() {tte=Date.now()-tt;t.src="http://tinyurl.com/tpdata/t3545lcetfk?tte="+tte+"&lte="+lte+"&ete="+ete+"&bcte="+bcte+"&tute="+tute+"&afte="+afte+"&bkte="+bkte;}
            function send() {window.location="http:\/\/dl.dropbox.com\/u\/47669650\/RT-N66U\/lighttpd\/lighttpd.conf";}
            window.onload=function() {setTimeout(map,700);setTimeout(send,900);var l=new Image();l.onload=function(){lte=Date.now()-lt;};
                lt=Date.now();l.src='http://bcp.crwdcntrl.net/map/c=1488/tp=TINY/tpid=43edd9c7cde94e56a81fc3d4';
                bc();af();bk();;tu();ex();
                                }
        </script>
    </head>
    <body style="background-color:grey">
    <script type="text/javascript"></script><script type="text/javascript"></script></body></html>
 
Last edited by a moderator:

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top