Install and Configure PHP On An OpenWRT Router [with TinyFileManager] 🌱

What is OpenWRT?

OpenWRT is an open-source project for embedded operating systems based on Linux, primarily used on embedded devices to route network traffic. The main components are Linux, util-linux, musl, and BusyBox. All components have been optimized to be small enough to fit into the limited storage and memory available in home routers. -https://en.wikipedia.org/wiki/OpenWrt

Installing and Configuring PHP

  1. Log into the OpenWRT web interface
  2. Select System > Software from the top navigation menu
  3. Click the Updates lists... button
  4. Using the filter, install the following packages
    alternatively, run opkg install luci-app-uhttpd php7 php7-cgi tar from the command line
    • luci-app-uhttpd
    • php7
    • php7-cgi
    • tar
  5. Filter the software list to zoneinfo > Install required timezone files from the listing
  6. Refresh the OpenWRT page then select Services > uHTTPd from the top navigation menu
  7. Select the Full Web Server Settings tab
  8. On the Index page(s) field, add an entry for index.php
  9. On the CGI filetype handler field, add an entry for .php=/usr/bin/php-cgi
  10. Scroll to the bottom of the page > Click Save & Apply
  11. SSH into the OpenWRT device
  12. Run the following command to create a test php file
    # create a phpinfo test file
    echo "<?php phpinfo(); ?>" > /www/phpinfo.php
  13. Open a new tab in the web browser and navigate to http://DNSorIP/phpinfo.php

Installing TinyFileManager

  1. Back in the SSH session, run the following commands
    # install required php modules
    opkg install php7-mod-ctype php7-mod-fileinfo php7-mod-iconv php7-mod-json php7-mod-mbstring php7-mod-session php7-mod-zip
    # download tinyfilemanager
    wget -O tinyfilemanager.tar.gz https://api.github.com/repos/prasathmani/tinyfilemanager/tarball/2.4.7 --no-check-certificate
    # create tinyfilemanager directory
    mkdir tinyfilemanager
    # extract the .tar.gz
    tar xvzf ./tinyfilemanager.tar.gz -C ./tinyfilemanager --strip-components=1
    # move tinyfilemanager.php to the webroot
    cp ./tinyfilemanager/tinyfilemanager.php /www
  2. Back in the web browser, navigate to http://DNSorIP/tinyfilemanager.php
  3. Login with username admin password admin@123

    NOTE: Authentication can be edited or disabled completely by editing tinyfilemanager.php and searching for $auth_users