I've tried to open my PHP script in the built in Android browser, but I only see my code, as text, and the PHP doesn't run. Why is that ?
How can I run PHP on my Android device ? Is there a way to set up PHP and a web server on an Android device ?
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.
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 to http://127.0.0.1:8080
with 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.