Hosting web applications on OpenWrt

I want to develop a couple of almost trivial web applications, and was thinking to host them on my OpenWrt device; these are not LuCi extensions, but I just think it would be nice not having to use a separate device.

Under other circumstances, I would just code them in PHP and call it a day, but I think PHP is way overkill for my device, and OpenWrt already has its own application server. However, I am not sure if the current server is ready to host arbitrary applications, or is very oriented towards LuCi.

If I could find a "hello world tutorial" on this, I would be very grateful.

Hi Edu, I think golang may be an option

package main

import (

func main() {
    http.HandleFunc("/", HelloServer)
    http.ListenAndServe(":8080", nil)

func HelloServer(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
    fmt.Printf("Hello, %s!\n", r.URL.Path[1:])

Compile go code

GOOS=linux GOARCH=mips GOMIPS=softfloat go build -ldflags "-w" main.go


BusyBox v1.28.4 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 OpenWrt 18.06.3, r7798-97ae9e0ccb
root@306:~# /tmp/main 
Hello, world!


1 Like

Eduardo, which language do you want to write them in? If you are sure you want these apps outside of luci, you can start another uhttpd instance with your preferred parser and use that. That's what I've done with the fakeinternet where the actual code is a shell script.

It's not that complicated to add something to Luci if you're familiar with lua tho. The luci-app-advanced-reboot is a very simple app with just a controller and a few HTML view-files may help you as an example.

Many thanks for your answers!

I think I am going to go the lua way... even if I have never coded in it, so far it does not look overly complicated, seems way powerful enough for my purposes, and comes pre-installed on any OpenWrt device.

However, I would like to separate it completely from LuCi, and here is where I have trouble find a "hello world" example.

1 Like