Post Reply Subscribe to Thread Email Thread

[Guide] PHP Development on Android [14 Mar 2015]

14th March 2015, 11:20 PM |#1  
benkxda's Avatar
OP Recognized Contributor
Thanks Meter: 2,450
 
991 posts
Join Date:Joined: Jan 2012
Thread link
[Guide] PHP Development on Android

PHP Plus Android


WHAT?
Yes, you can develop with PHP on your Android device, no I am not mad (yet) - not guaranteed for lifetime. This guide is just to help you starting and hopefully kicks off some discussions about this (currently) not very common opportunity.



WHY the heck...?
Well, by now it's just playing with our devices, sure. But let's face it and let's see the potential of an Android device in the future, maybe in only a few years. Do I have to boot my computer or notebook or is it more likely I just wake my smartphone or tablet and give it a power source by placing it in the stand? Either way, it also makes fun playing around by now and using a maybe older device as a low power consuming web app server.



But PHP is ridiculous, scripting for kids, security flaws, inconsistencies, ugly syntax...
PHP is one of the most important scripting languages in the web. It's not perfect, sure, but you can create really big projects like Wordpress and vBulletin and therefore also our beloved XDA. However, this is a thread about how to start PHP developing on an Android device, not about how great or how bad this programming language is.


You have a question? Post it in the thread.
You have improvements? Post it in the thread.
You know better apps? Post it in the thread.
You don't like PHP? Well, move along...



My test set up

Hardware
Software/Apps
  • code editor
  • web server with PHP support

I develop and apply the programs locally, means, code editor and server are on the same device. Uploading or managing files remotely is not not required in this case.



Optional and recommended accessories and apps

Hardware
  • Bluetooth input devices, so you can charge your device
  • USB cable to charge your device, you'll need it
  • alternatively use wireless charging if your device supports it

Software/Apps
  • DynDNS client
  • port forwarder (needs root to forward to standard port 80)
  • SFTP/FTPS server/client
  • SSH server/client
  • server monitor

The apps will raise the battery consumption, so for longer development sessions, use Bluetooth keyboards and mice or a BT keyboard with an integrated touchpad. Charge your device.
DynDNS client makes your device available to the internet using a simple subdomain name instead of the ip address. The port forwarder can redirect incoming HTTP requests to port 80 for example. To upload and manage your files from your Android device to a web server from your web hoster, you can use secured FTP (SFTP/FTPS) and SSH clients or use servers, if you upload from an Android to an Android device.
Last edited by benkxda; 16th March 2015 at 12:24 AM.
14th March 2015, 11:21 PM |#2  
benkxda's Avatar
OP Recognized Contributor
Thanks Meter: 2,450
 
991 posts
Join Date:Joined: Jan 2012
Code editors

To write code, you'll need code editors and some of them are quite good for doing that. Try some of these following, if you don't have any yet.

AIDE Web - Html,Css,JavaScript - paid: IAP
Updated: December 11, 2014
Current Version: 1.0.3beta

AWD - PHP/HTML/CSS/JS IDE - paid: IAP
Updated: April 9, 2014
Current Version: 0.38
XDA application thread by @divers

DroidEdit (free code editor) - paid: DroidEdit Pro (code editor))
Updated: March 03, 2015
Current Version: 1.23.0

Quoda Code Editor - paid: IAP
Updated: August 14, 2014
Current Version: 1.0.1.2

Turbo Editor ( Text Editor ) - paid: IAP, Turbo Editor PRO (Text Editor)
Updated: March 14, 2015
Current Version: 1.15.1
XDA application thread by @Vlad Mihalachi



Web servers with PHP support

Some web servers with integrated PHP interpreter are listed below. A lot of those on Google Play have a free trial period, so try before you buy.
Down below you find three free web servers with PHP interpreter. I also checked which server software they're running and it's version, as well as the version of the PHP interpreter.

AndroPHP
Updated: February 8, 2013
Current Version: 1.2.0
Web server: Lighttpd 1.4.29
PHP version: 5.4.8
View the complete output of phpinfo() as PDF (196 kB)

AndroPHP AndroPHP


Palapa Web Server
Updated: August 26, 2014
Current Version: 2.1.1
Web server: Lighttpd 1.4.32
PHP version: 5.5.15
View the complete output of phpinfo() as PDF (291 kB)

Palapa Web Server Palapa Web Server


Server for PHP
Updated: February 7, 2015
Current Version: 1.6.4
Web server: PHP 5.6.3 Development Server
PHP version: 5.6.3
View the complete output of phpinfo() as PDF (344 kB)

Server for PHP Server for PHP



This one is basically a server collection, tons of servers for all your needs. Slightly outdated, no update for quite a long time, therefore an old PHP version. Hopefully the app gets new and updated servers. Trial version available.
Servers Ultimate (7 days trial) - paid: Servers Ultimate Pro
Updated: June 16, 2014
Current Version: 6.3.10
Web server: Lighttpd
PHP version: 5.4.8
View the complete output of phpinfo() as PDF (197 kB)
XDA application thread by @Themuzz

Servers Ultimate Pro Servers Ultimate Pro



Web server monitor

To monitor your mobile web server, I recommend to set up a server monitor app, like Monyt - Server Monitor. The app itself is a client, pulling information from a script you have to place on your server. Just for the records, it's a PHP script.

Monyt - Server Monitor
Updated: March 15, 2013
Current Version: 1.1.4
XDA application thread by @evilsocket
  • Install Monyt - Server Monitor from Google Play store (on any Android device, this is basically only the client)
  • Paste the PHP code into a *.php file (link in the Google Play description) (on the server)
  • Configure the app, at least enter the URL to the PHP script
The monitor app can also be installed on your mobile server.

Some screenshots made on a Sony Xperia Z3

Monyt Monyt Monyt


Current link and content of the PHP script: http://www.monyt.net/monyt-server-script.txt
PHP Code:
<?php

error_reporting
(0);

define"MONYT_SCRIPT_VERSION""1.0.1" );

if( isset(
$_GET['version'] ) )
{
    die( 
MONYT_SCRIPT_VERSION );
}
else if( isset(
$_GET['check']) )
{
    
$aCheck = array
    (
        
'monyt' => MONYT_SCRIPT_VERSION,
        
'distro' => '',
        
'kernel' => '',
        
'cpu' => '',
        
'cores' => ''
    
);
    
    
$sDistroName '';
    
$sDistroVer  '';

    foreach (
glob("/etc/*_version") as $filename
    {
        list( 
$sDistroName$dummy ) = explode'_'basename($filename) );

        
$sDistroName ucfirst($sDistroName);
        
$sDistroVer  trimfile_get_contents($filename) );
        
        
$aCheck['distro'] = "$sDistroName $sDistroVer";
        break;
    }
    
    if( !
$aCheck['distro'] )
    {
        if( 
file_exists'/etc/issue' ) )
        {
            
$lines file('/etc/issue');
            
$aCheck['distro'] = trim$lines[0] );
        }
        else
        {
            
$output NULL;
            
exec"uname -om"$output );
            
$aCheck['distro'] = trimimplode' '$output ) );
        }
    }
    
    
$cpu file'/proc/cpuinfo' );
    
$vendor NULL;
    
$model NULL;
    
$cores 0;
    foreach( 
$cpu as $line )
    {
        if( 
preg_match'/^vendor_id\s*:\s*(.+)$/i'$line$m ) )
        {
            
$vendor $m[1];
        }
        else if( 
preg_match'/^model\s+name\s*:\s*(.+)$/i'$line$m ) )
        {
            
$model $m[1];
        }
        else if( 
preg_match'/^processor\s*:\s*\d+$/i'$line ) )
        {
            
$cores++;
        }
    }
    
    
$aCheck['cpu']    = "$vendor$model";
    
$aCheck['cores']  = $cores;
    
$aCheck['kernel'] = trim(file_get_contents("/proc/version"));
    
    die( 
json_encode($aCheck) );
}

$aStats = array( 'monyt' => MONYT_SCRIPT_VERSION );


$aStats['uptime'] = trimfile_get_contents("/proc/uptime") );

$load file_get_contents("/proc/loadavg");
$load explode' '$load );

$aStats['load'] = $load[0].', '.$load[1].', '.$load[2];

$memory file'/proc/meminfo' );
foreach( 
$memory as $line )
{
    
$line trim($line);
    
    if( 
preg_match'/^memtotal[^\d]+(\d+)[^\d]+$/i'$line$m ) )
    {
        
$aStats['total_memory'] = $m[1];
    }
    else if( 
preg_match'/^memfree[^\d]+(\d+)[^\d]+$/i'$line$m ) )
    {
        
$aStats['free_memory'] = $m[1];
    }
}

$aStats['hd'] = array();

foreach( 
file('/proc/mounts') as $mount )
{
    
$mount trim($mount);
    if( 
$mount && $mount[0] == '/' )
    {
        
$parts explode' '$mount );
        if( 
$parts[0] != $parts[1] )
        {
            
$device $parts[0];
            
$folder $parts[1];
            
$total  disk_total_space($folder) / 1024;
            
$free   disk_free_space($folder) / 1024;

            if( 
$total )
            {
                
$used   $total $free;
                
$used_perc = ( $used 100.0 ) / $total;

                
$aStats['hd'][] = array
                (
                    
'dev' => $device,
                    
'total' => $total,
                    
'used' => $used,
                    
'free' => $free,
                    
'used_perc' => $used_perc,
                    
'mount' => $folder
                
);
            }
        }
    }
}

$ifname NULL;

if( 
file_exists('/etc/network/interfaces') )
{
    foreach( 
file('/etc/network/interfaces') as $line )
    {
        
$line trim($line);

        if( 
preg_match'/^iface\s+([^\s]+)\s+inet\s+.+$/'$line$m ) && $m[1] != 'lo' )
        {
            
$ifname $m[1];
            break;
        }
    }
}
else
{
    foreach( 
glob('/sys/class/net/*') as $filename )
    {
        if( 
$filename != '/sys/class/net/lo' && file_exists"$filename/statistics/rx_bytes" ) && trimfile_get_contents("$filename/statistics/rx_bytes") ) != '0' )
        {
            
$parts explode'/'$filename );
            
$ifname array_pop$parts );
        }
    }
}

if( 
$ifname != NULL )
{
    
$aStats['net_rx'] = trimfile_get_contents("/sys/class/net/$ifname/statistics/rx_bytes") );
    
$aStats['net_tx'] = trimfile_get_contents("/sys/class/net/$ifname/statistics/tx_bytes") );
}
else
{
    
$aStats['net_rx'] = 
    
$aStats['net_tx'] = 0;
}

die( 
json_encode$aStats ) );

?>
Last edited by benkxda; 15th March 2015 at 01:17 AM.
14th March 2015, 11:21 PM |#3  
benkxda's Avatar
OP Recognized Contributor
Thanks Meter: 2,450
 
991 posts
Join Date:Joined: Jan 2012
Reserved
Post Reply Subscribe to Thread

Tags
android, code, development, php, server
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes