Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Tuesday, March 20, 2012

PAW Runtime & PHP

PAW Runtime has been updated to support PHP.
To install PHP for the runtime version of PAW, download the file PawRuntime_PHP_Setup.zip (link below) and unzip it to /sdcard of your Android device.

After starting PAW Runtime a PHP menu entry should be available.
After selecting the entry the page shown below should appear...

PHP Setup
Make your selections and press the Install button. PHP should be available after a restart of PAW Runtime.

If you wold like to get rid of unnecessary files and the menu entry, you can delete the file /sdcard/paw-runtime/webconf/apps/php_setup.conf and everything inside the  /sdcard/paw-runtime/html/php_setup directory except the conf directory.

Links
PAW Runtime
PHP Setup

Update
If you have problems to download above files from the original source, try to use the alternative RapidShare links below:
http://rapidshare.com/files/1766553424/PawRuntime.apk
http://rapidshare.com/files/3080577482/PawRuntime_PHP_Setup.zip

Thursday, November 24, 2011

PHP Plug-in Update

My cross compiled version of the PHP CGI was not working so well and I didn't manage to fix it.

Fortunately Klaas Biker informed me that Iulian Virtejanu has cross compiled a PHP CGI version that seems to work significantly better.
Here is Iulian's blog entry: PHP and Lighttpd for Android

Iulian gave me the permission to use it in PAW, so I have updated the PHP Plug-in to version 0.3.

There is one known issue:

system(...) does not work.
It is because system('pwd') actually invokes a hardcoded /bin/sh -c 'pwd' - and /bin/sh is not available on Android.
Iulian has submitted a bug report to PHP: https://bugs.php.net/bug.php?id=60081

If you find more bugs, please let me know. I will forward them.

Monday, October 31, 2011

Building PHP from Scratch

This post by Rahul Amaram describes how to build PHP for Android from scratch and how it can later be used within PAW.
I've added links to the needed files at the end of the post.

Thanks to Rahul for putting this together!

Here is Rahul's documentation...



It is suggested to use a VM for compilation so that you can take snapshots at regular intervals. Also as per google recommendation, it is suggested to use a VM with at least 8 GB RAM/swap and 12 GB of free hard disk.

Install Ubuntu 10.04 64-bit (select username as "joschi") on a VM.

After booting ubuntu, login as joschi.

Download and extract android-php

$ cd
$ wget -c "http://paw-android.fun2code.de/download/android-php.zip"
$ sudo apt-get install unzip
$ unzip android-php.zip

First initialize build environment. For donut, java 5 is needed. Also compiling with gcc/g++ 4.4 was throwing errors during compilation. Therefore we use gcc/g++ 4.3 for compilation.

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk


$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils


$ sudo apt-get install g++-4.3-multilib

Download Android source
This will be about 3 GB.

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
$ chmod a+x ~/bin/repo


$ mkdir ~/android-donut-src
$ cd ~/android-donut-src
$ repo init -u https://android.googlesource.com/platform/manifest -b android-1.6_r2
$ repo sync

It is a good idea to take snapshot of the VM here.

Build Android

$ cd /usr/bin
$ sudo ln -sf cpp-4.3 cpp
$ sudo ln -sf g++-4.3 g++
$ sudo ln -sf gcc-4.3 gcc
$ sudo ln -sf gcov-4.3 gcov
$ sudo ln -sf cpp-4.3 x86_64-linux-gnu-cpp
$ sudo ln -sf g++-4.3 x86_64-linux-gnu-g++
$ sudo ln -sf gcc-4.3 x86_64-linux-gnu-gcc


$ cd ~/android-donut-src
$ source build/envsetup.sh
$ lunch generic-eng
$ make -j4

It is a good idea to take another snapshot of the VM here.

Next build android-php. The patch is applied in order to avoid the error "undefined reference to `__sync_fetch_and_add_4'" during compilation.

$ cd ~/android-php
$ rm -rf ~/android-donut-src/bionic/libc/include/
$ unzip -d ~/android-donut-src/bionic/libc/ bionic_libc_include.zip
$ patch php-5.3.6/ext/standard/php_crypt_r.c < ~/sync_fetch_and_add.patch
$ ./build_php_5.3.sh

Finally copy php-5.3.6/sapi/cgi/php-cgi to /mnt/sdcard/paw/html/app/plugins/php_plugin/bin/ on your android phone (be sure to backup the existing php-cgi file), and install PHP using the PAW Web App.

References:



Files:
android-php.zip
sync_fetch_and_add.patch

Thursday, April 21, 2011

PAW Server & PHP

In this post I would like to write about what is coming up next in PAW development.
PAW supports BeanShell code to create dynamic pages. BeanShell is well suited for Android, because it integrates will into the OS by supporting the Android Java API.

The foundation of PAW is Brazil a web application framework which was developed by SUN (now Oracle). Although not widely used the framework has the advantage of being very small and flexible.
What I was thinking about for a while was to add PHP support. PHP is widely used  around the net. PHP's reputation is questionable and that are people who love and others who hate it. But it's undoubtedly one of the most used frameworks when it comes to web development.

PHP basically comes in two flawors, a CLI and a CGI version. To integrate PHP into the context of a web server the CGI version is needed.

Android PHP Project
Knowing that there is a CLI version provided by the Android PHP Project I headed over to their forum asking if they could provide a CGI version in addition to the CLI version.

Unfortunately the guys told me that a CGI version will not be provided by the project because it's not needed and pointed me to a page which describes shortly how to setup the tool-chain to do a cross compile of PHP.

Cross Compiling
So I tried to compile PHP myself. I have a Linux box at home so I'm quite familiar with doing configure/make and all this things but the last time I dug into C sources and header files is approx. 10 years back. So this was quite a challenge. Finally I got it working, but I think I did a lousy job. So if somebody can do it better, please go ahead and send me the php-cgi binary.

The CGI Handler
After I had the binary I extended and changed the CGI handler that is included with Brazil to work with Android. Due to some changes in the Brazil source that I have done concerning upload size limits the original handler could not be used. In the process I also tried to add SL4A support. I haven't tested this until know, but I hope it will be working.

SL4A Support
SL4A support is a little bit tricky, because one has to know the port the SL4A is listening to. So I looked around how to get hold of the port and found out that the port is reported in the logcat.
So on startup of the handler (on start of the PAW service) the handler looks into logcat and tries to find the SL4A host name and port number. These values are associated with the AP_HOST and AP_PORT environment variables. So SL4A the server has to be started shortly before PAW starts up.

The Plugin
PHP will be available as plugin shortly after the next release of PAW (which should be in the next month). PAW will then come with the new handler. Providing PHP as plugin has the advantage that PAW itself does not grow (much) in size. PHP is approx. 3 MB in size and so relatively large.
The plugin can be downloaded from an external website and extracted into the PAW plugin folder.
A new page showing available plugins will be included into the next PAW release.

Plugins in the Add-Ons menu


After extracting the plugin it should be visible under PAW's plugin menu.

Plugin in the Plug-ins menu


Installation of PHP should be a one click action and after a restart of PAW PHP should be available.

PHP Installation

PHP has been tested using a Google Nexus One and a Notion Ink Adam. The result of phpinfo() can be viewed here.

This is work in progress but it looks promising although not all PHP pages will be working but basic stuff should.

So stay tuned, I hope to finish this in a couple of weeks :)

Note:
PAW for Android 0.58 is now available at the Android Market.
The PHP plug-in is also available.

Update
If you have trouble downloading the PHP plugin from the original location, you can try the alternate link at Google Drive: PAW Plugins