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 php7-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...

  • Alessio Petrolino

    After installing it AIcloud stop responding, if i stop lighttpd it start working again, how can I make them AIcloud working again. no way to make them work at same time, both lan or wan. Any suggestion
    ?

    • After reboot, if you restart lighttpd, aicloud it's working?

      • Alessio Petrolino

        no, still same , to make AIcloud work I need to stop lighttpd

        • TeHashX

          Change lighttpd port from 81 to 83 and try again

          • Alessio Petrolino

            still same, when i reboot aicloud is ok, lighttpd if I try to connect give me error ERR_CONNECTION_REFUSED
            If i give command to restatt lighttpd, the it works but aicloud give me ERR_CONNECTION_REFUSED , if I send /S80l
            ighttpd stop then aicloud work again...
            I'm on entware-ng

          • Alessio Petrolino

            PS on asus asus rt-ac68 latest merlin firmware

          • Alessio Petrolino

            NO suggestion :-(

          • Alessio Petrolino

            can you guide me to remove it as is not woking?

          • I have no idea why they are not working together.
            To remove lighttpd
            opkg remove lighttpd

  • Huib

    On a RT-AC68U, running Asuswrt-Merlin 380.68_2, I installed Entware. Did opkg upgrade to make sure it was up to date.

    I followed the tutorial above but was forced to change php5 to php7 because php5 is no longer offered. All packages are installed now:

    lighttpd - 1.4.45-7
    lighttpd-mod-fastcgi - 1.4.45-7
    php7 - 7.1.9-1
    php7-cgi - 7.1.9-1
    php7-fastcgi - 7.1.9-1

    First error I get is:

    admin@asus:/tmp/home/root# lighttpd -f /opt/etc/lighttpd/lighttpd.conf
    2017-10-01 17:17:36: (configfile.c.1037) opening configfile /opt/etc/lighttpd/conf.d/*.conf failed: No such file or directory
    2017-10-01 17:17:36: (configfile.c.995) source: /opt/etc/lighttpd/lighttpd.conf line: 30 pos: 1 parser failed somehow near here: (EOL)

    Okay, so I change *.conf to 30-fastcgi.conf since it's my only conf file for the moment.

    Now I get:

    admin@asus:/tmp/home/root# lighttpd -f /opt/etc/lighttpd/lighttpd.conf
    2017-10-01 17:18:14: (plugin.c.223) dlopen() failed for: /home/merlin/asuswrt.ac68/release/src/router/lighttpd-1.4.39/_inst/lib/mod_fastcgi.so File not found
    2017-10-01 17:18:14: (server.c.718) loading plugins finally failed

    Don't know where this whole path (/home/merlin/asuswrt.ac68/release/src/router/lighttpd-1.4.39/_inst) comes from but the module does in /opt/lib/lighttpd

    Created the path/folder /home/merlin/asuswrt.ac68/release/src/router/lighttpd-1.4.39/_inst/lib and dropped mod_fastcgi.so in it but still no joy.

    So at the moment I'm stuck and so far Google hasn't been my usual friend. Any help is appreciated.

    • You only have to change from php5-fastcgi to php7-fastcgi and will install fine.
      Start with new entware installation.

  • 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?

Get Email Notification When a Server or Port is Unreachable
SoftEther VPN Running on AsusWRT Routers
Minidlna UPnP Media Server through Debian Jessie Arm
How to Mount Samba Shares inside Chrooted Debian
Minidlna UPnP Media Server through Debian Jessie Arm
How to Mount Samba Shares inside Chrooted Debian
Spreed WebRTC server and web client
Asterisk VoIP Server running on AsusWRT Routers
Get Email Notification When a Server or Port is Unreachable
SoftEther VPN Running on AsusWRT Routers
NZBGet through Entware
Minidlna UPnP Media Server through Debian Jessie Arm

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...