Search code examples
phpopenwrt

How to install and configure php in openwrt


I have developed some pages in PHP and HTML. But the PHP pages were not working when I put these pages in OpenWrt www folder. I have installed php5 in OpenWrt. These pages were working fine with apache localhost in ubuntu. In OpenWrt, It has uHTTPd. Do I need to install anything other than just php5 (other modules) or Do I need to configure something?


Solution

  • For PHP5 configuration on OpenWRT see: http://wiki.openwrt.org/doc/uci/uhttpd

    First, install PHP

    opkg update
    opkg install php5
    opkg install php5-cgi
    

    Install any other additional php5 extensions you may use. To see available packages:

    opkg list php5*
    

    Example:

    opkg install php5-mod-sockets
    

    Open your /etc/php.ini and uncomment any of the extensions you just installed. Continuing with the sockets example above the following:

    ;extension=sockets.so
    

    becomes

    extension=sockets.so
    

    Now open /etc/config/uhttpd and add the following line:

    list interpreter ".php=/usr/bin/php-cgi"
    

    Don't forget to restart uhttpd:

    /etc/init.d/uhttpd restart
    



    One option in regards to your space (flash) limitations of installing PHP on your embedded device: if you have access to a USB port on your embedded device (like many do) you can set up your base openWRT configuration with extroot. Essentially you will boot to a USB drive thereby enabling all of the space of the USB drive to install packages and add files. See: http://wiki.openwrt.org/doc/howto/extroot