Click here if you want to keep alive this site, thanks!    This site will go offline starting with 01-JUL-2017 when web hosting contract expires, I don't have free time and interest anymore to maintain it. You have permission to copy all tutorials, one by one, and post them somewhere else like RMerlin Wiki.

Lighttpd Web Server with PHP Support through Entware-NG

1 - Install Entware-NG from here

2 - Install lighttpd

opkg install lighttpd

3 - Choose 81 as lighttpd server port and fix uploads directory

sed -i 's/#server.port                 = 81/server.port                 = 81/g' "/opt/etc/lighttpd/lighttpd.conf"
sed -i "/server.upload-dirs*/cserver.upload-dirs          = ( \"/opt/tmp\" )" "/opt/etc/lighttpd/lighttpd.conf"

4 - Restart server

/opt/etc/init.d/S80lighttpd restart

5 - Create test page

cat >> /opt/share/www/index.html << EOF
<html>
<head>
<title>lighttpd default page</title>
</head>
<body>
<h2>lighttpd server is running.</h2>
</body>
</html>
EOF

Press ENTER

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

7 - Create php info page

cat >> /opt/share/www/info.php << EOF
<?php
phpinfo();
?>
EOF

Press ENTER

8 - Install PHP

opkg install lighttpd-mod-fastcgi php5-fastcgi

9 - Enable PHP

cat >> /opt/etc/lighttpd/conf.d/30-fastcgi.conf << EOF
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" =>
( "localhost" =>
( "socket" => "/tmp/php-fcgi.sock",
"bin-path" => "/opt/bin/php-fcgi",
"max-procs" => 1,
"bin-environment" =>
( "PHP_FCGI_CHILDREN" => "2",
"PHP_FCGI_MAX_REQUESTS" => "1000" )
)
)
)
EOF

Press ENTER

10 - Restart server

/opt/etc/init.d/S80lighttpd restart

11 - Go to 192.168.1.1:81/info.php and if you see this page, php is configured correctly

12 - Enable access from wan

nano /jffs/scripts/firewall-start

Paste this lines

#!/bin/sh
iptables -I INPUT -p tcp --destination-port 81 -j ACCEPT
Save with CTRL-O / Enter / and exit with CTRL-X
Make script executable and apply rule
chmod a+rx /jffs/scripts/firewall-start
/jffs/scripts/firewall-start

13 - Go to Port Forwarding page http://192.168.1.1/Advanced_VirtualServer_Content.asp and redirect port 80 to 81

lighttpd-portfw

Enjoy...

  • Mario

    Hello, how do I put lighttpd in? Previously I worked on asus rtn-66u and after installing everything on asus rt-ac68 install the module with:
    Opkg install lighttpd-mod-auth
    And I modified the file lighttpd.conf with:

    server.modules += ( "mod_auth" )
    auth.backend = "plain"
    auth.backend.plain.userfile = "/opt/etc/lighttpd/passwd"
    auth.require = (
    "" =>
    ( "method" => "basic",
    "realm" => "restricted area",
    "require" => "valid-user"
    )
    )

    But it does not work, can anyone help me?

    Thank you

    sorry for my English

  • Anonymous

    Same here. AiCloud not working anymore whenever lighttpd/owncloud is up. Please help

  • light

    After install lighttpd, cannot connect Aicloud.

    1. reboot router, that time can use Aicloud
    2. 5min later turn on lighttpd then close the connect of Aicloud...

    What I should do to use both lighttpd and Aicloud??

    • You can't connect from lan or wan?

  • Ken

    Would it be possible to install php 7 instead of php 5?

  • sugarmoose

    I'm having trouble accessing the lighttpd web server after setting it up. I can connect to the server within the router (while logged-in in SSH via lynx localhost:81) but no such luck accessing it via the LAN or WAN. I've enabled port forwarding on 80 -> 81, and enabled the iptables script. Anything else I can try?

    Asuswrt-Merlin: 380.59
    Asus RT-AC68U
    Entware-NG

    • TeHashX

      Reboot router or execute
      sh /jffs/scripts/firewall-start

      • sugarmoose

        I've rebooted a couple times and started the firewall-start script, but still can't access the web server on port 80. I'm able to connect via my WAN IP to port 22 (ssh) and port 8443 (ssl web admin), so it seems like enabling WAN access via the web-admin works... but not via the iptables script. Is there a log file to tell me if there's an error with iptables or something else?

        If all else fails, I'll try to reflash my router and start from scratch.

      • TeHashX

        You can't access lighttpd from port 80 because is used by router, access through port 81 or choose another at step 3.
        Another way is to access by https, in this case don't need to input port 81 anymore.

      • sugarmoose

        Thanks for the reply.
        Unfortunately, I'm unable to access lighttpd via 81 or 80 or anything else (after running the iptables script and port forwarding). I might try setting up https as you suggested.
        By the way, is there a way to disable the default router's web server on port 80 (so that another web server can use it)?

      • TeHashX

        Can't disable built in lighttpd because is used for UI, install from scratch and should work but first try with another web browser, maybe neen to clear cache.

  • TheOpenSourceTV

    Hi, Im trying to install PHPMyAdmin on Entware-ng and it almost works. The login screen appears and shows an error after trying to login with correct user and pass:
    #2002 - Can't connect to local MySQL server through socket '/opt/tmp' (146)The server is not responding (or the local server's socket is not correctly configured).
    Any ideas how to fix this? Thanks.

    • TeHashX

      Did you created a mysql password right after installing?

SUBSCRIBE

To be notified by email when a new tutorial is posted :)

Thanks for Subscribing! I'll keeping you up-to-date with latest tutorials!

Something went wrong, try again...