How I fixed OpenWRT LuCI error /etc/config/luci seems to be corrupt, unable to find section ‘main’

Problem:

When you try to open your OpenWRT Web UI, you see an error message like

/usr/lib/lua/luci/dispatcher.lua:427: /etc/config/luci seems to be corrupt, unable to find section 'main'

Solution:

In my case, the issue was a bad rpcd configuration which I restored from an older OpenWRT version that contained the config line

option socket /var/run/ubus.sock

instead of the correct

option socket /var/run/ubus/ubus.sock

You can replace your rpcd config by the default by running the following command over SSH:

cp /rom/etc/config/rpcd /etc/config/rpcd

and then

reboot