PHP

From NMTWiki

Jump to: navigation, search

Image:Redvsmall.jpg Difficult - for advanced users, may require detailed technical knowledge, use at your own risk!

Applicable only for the following:
PCH NMT models: A100/110/B110
Others NMT's: HDX/eGreat

While there are some limitations, it is certainly possible to run PHP scripts on the NMT devices. Other than the requirement for a hard disk with the NMT Applications installed, there are no modifications you need to make or third party software you need to install.

There are two separate methods each providing a different version of PHP and each having both advantages and drawbacks.


Contents

Running PHP as a CGI script

The internal webserver of the NMT is able to execute CGI scripts. The CGI version of PHP 5 is available if you installed the NMT Applications.

To run PHP scripts you need to do the following:

  • Make sure the php script has the file extension .cgi, for example create a file named index.cgi in the root of the hard disk.
  • Make sure the file has UNIX line endings, Check your editor. see Unix_Friendly_Text_Editor
  • Make sure the file has executable rights, which can be done using a proper ftp client or telnet, for example using telnet:
cd /opt/sybhttpd/localhost.drives/HARD_DISK
chmod a+x index.cgi

Files on network shares and USB drives always have executable rights, so you only have to do this step if you want to run scripts from the internal hard drive.

  • Include the path to the php binary on top of the file, for example:
#!/mnt/syb8634/server/php5-cgi
<?php

phpinfo();

?>
  • Use a HTML file to redirect to the cgi file using a normal link, or a meta refresh:
<meta http-equiv="refresh" content="0;http://localhost.drives:8883/HARD_DISK/index.cgi">

Details

Based on the firmware 01-17-081023-15 (NMT 00-17-081023-15)

PHP 5.2.6 with the following extensions available: cgi, ctype, date, dom, filter, hash, iconv, json, libxml, pcre, PDO, pdo_sqlite, posix, Reflection, session, SimpleXML, sockets, SPL, SQLite, standard, tokenizer, xml, xmlreader, xmlwriter

Advantages

  • Running as the root user, so you can access anything
  • You get to use the modern PHP 5
  • Your are able to read SQLite 3 databases using PDO

Drawbacks

  • Only accessible from the NMT itself, you can't build publicly accessible pages with this method

Running PHP using the /stream=/ hack

If you installed the NMT Applications and are running the build-in myiHome Server, you can directly run a PHP file on your NMT using a specially crafted URL. For example to access a file called index.php in the root of you hard disk you can use the following URL:

http://localhost:8088/stream/file=/opt/sybhttpd/localhost.drives/HARD_DISK/index.php

To access this URL from the NMT you need to create a HTML file with a link or meta refresh, for example:

<meta http-equiv="refresh" content="0;http://localhost:8088/stream/file=/opt/sybhttpd/localhost.drives/HARD_DISK/index.php">

You can also use this method to create pages that are accessible from outside the NMT. This is especially useful if you want to create a web application that runs on your NMT, but is accessed from a computer in your network, or even from the internet. Just change the localhost in the URL above with the IP address of your NMT, for example:

http://192.168.1.3:8088/stream/file=/opt/sybhttpd/localhost.drives/HARD_DISK/index.php

Details

Based on the firmware 01-17-081023-15 (NMT 00-17-081023-15)

PHP 4.3.8 with the following extensions available: Turck MMCache, apache, ctype, file64, overload, pcre, posix, session, sqlite, standard, thumb, tokenizer, xml, zlib.

Advantages

  • Publicly accessible
  • No messing around with file permissions

Drawbacks

  • Only available if myiHome Server is running on the NMT
  • Running as a regular user, so you don't have full access to the whole machine
  • You get to use an older version of PHP
  • Your are not able to read SQLite 3 databases
Personal tools