Replace LuCI with a custom PHP webpage

Hi, I'm trying to replace the LuCI page with a custom PHP web page.

As a noob:

  1. I installed php7
  2. renamed /www/index.html (with the redirection to LuCI inside?) in luci.html
  3. insert my PHP page with all the relative folders inside /www
  4. and finally reboot hoping everything worked at this first rough attempt.

Obviously it does not work: the browser displays the contents of the /www folder but clicking index.php the page does not open instead the download of the page starts.
What are the best practices for doing this?
what needs to be changed in the configuration files?
what additional software is needed?

I thank you for your help and I hope this answer can also be useful to other users.

Why so much hate and pain in the world? :wink:

You'll need to teach the webserver how to handle php files, just like you would on a normal webserver.
See this answer on StackOverflow

2 Likes
opkg list-installed | grep -q 'php7-cgi' || opkg update && opkg install php7-cgi

cp /etc/config/uhttpd /root/conforg-uhttpd

uci -q set uhttpd.main.index_page='index.html index.htm default.html default.htm index.php'
uci -q set uhttpd.main.interpreter='.php=/usr/bin/php-cgi'
uci commit uhttpd

/etc/init.d/uhttpd restart

thank you so much! it is a world full of hate and pain!
I write below the dirty procedure, maybe someone could come in handy:

  1. install the things you need:
    opkg install php7 php7-cgi php7-mod-session php7-mod-json
    In my case i need json stuff
  2. upload the site and all its stuff into /www, modify/rename/delete pre-existing index.html, what makes LuCI open
  3. open /etc/php.ini and verify that "doc_root" is empty, otherwise empty it
  4. open /etc/config/uhttpd and insert/modify "option index_page index.php" so that it loads the PHP page (otherwise it opens the index.html)
    and activate PHP by uncommenting:
    list interpreter ".php = / usr / bin / php-cgi"
  5. restart the /etc/init.d/uhttpd restart service or the whole device
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.