PHP is a language that is used on a web server (http server), not on a web client (browser). This means that in order to run PHP on your android device (and not just display a web page served from a web server hosted elsewhere, online), you need to install a web server on your device. Luckily there's a few apps which provide this functionality.
Web Server PHP/MyAdmin/MySQL
AWebServer ( Http Web Server A
In the past, I've had success with the free Palapa Web Server which is essentially a web / mysql server which runs on Android, which will run your PHP scripts, and it will also work offline. But this one no longer exists.
To use Palapa web server, install the app, and copy your PHP / HTML files onto your phone. By default, the Palapa Web server uses
/sdcard/pws/www/, so if you put your files there, it should pick them up. Then, launch the app, click "Start server", and go tohttp://127.0.0.1:8080with your web browser on your android device, and it should work. Other web server apps will work similarly.
Note that setting up PHPMyAdmin, (if you need that for managing databases) can be a bit tricky, as you will need to download the extra packages for it, if the app you're using does not bundle it.
Answer from Jonas Czech on Stack OverflowVideos
UPDATE AS OF JUNE 2, 2021
Option #1 ( Using CLI-based apks)
BEST OPTION
- Termux (Installation of PHP, MARIADB, PHPMYADMIN packages within termux)
- Terminal Emulator
- UserLand
Option #2 (Using GUI-based apks)
- KSWEB
- Servers Ultimate
Summary:
- The above-mentioned apks do not require rooted device.
- CLI-based apks are highly recommended because a user can use UPDATED version of PHP, Apache, and any other packages you want to install to. The KickWeb apk does support running .php files BUT ,unfortunately, it doesn't have the latest PHP VERSION. Using an outdated version of PHP makes some of your PHP code to throw errors or warnings etc.
I have tried KickWeb Server and it works as expected.
You almost certainly don't want to run PHP on your Android. But in case you do, then you would want http://code.google.com/p/php-for-android/. Better link: http://phpforandroid.net/
PHP is a server side language. It cannot run inside the browser. It helps you to build the dynamic web pages.
You can call any web page in the webview when you are online. it doesn't matter what is the server side language.
When you are offline, you cannot send request to any server. so no question of executing any page.
There are several options i found:
- http://phpforandroid.net/
- http://www.talkandroid.com/6211-php-for-android-install-it-and-start-testing/
Please note that i have not used these frameworks and have no idea how good they are.
Another option is develope in java and make HTTP calls to the php in certain occasions when needed.
One more option, is phonegap which allows you to develope android application using HTML,Javascript,CSS but that will require some changes to your existing application.
If you already have a working web application you can just access that with your android device. Maybe adapt the layout to fit well onto the smaller screen.
Without further work you cannot run PHP on an android phone, as you would need an interpreter (commonly a webserver).
Finally - someone has released the full package!
Bit Web Server (AMP; also see their homepage) stack running on Android. No hacking required. $2 to pay though!
If you are looking for a stack for iOS then the cydia-ios-lighttpd-php-mysql-web-stack does the trick: Should run lighttpd + php 5.4 + mysql - unfortunately only on jailbroken devices.
Edit: In case anyone is interested I have switched to Windows 8 tablet which happily runs all of the opensource AMP stacks. Runs very nicely and with a bit of Bootstrap styling I have a full feature sales order "app" for nothing. Little bit of code to sync back to the online version - no need to spend $50 per month per user on HandShake or similar.
If you're not stuck with PHP and MySql, then another option would be to use Html 5.
Then your site can run in the browser on iOS and (most) versions of android. By using offline cache and a local database, you could avoid using PhoneGap, etc. You could also use jQuery if you like.
You would, however, have to use javascript to access the local database instead of php. Also - since the sqlite support is being dropped in Html 5, you would have to use local storage or indexed db. I find the former much simpler and fine for my purpose.
BTW - for developing, Google Chrome has nice tools for debugging javascript.