-2

So I have been issued a project with tight restrictions, I need to run php files stored in local app directory for a WebView application. However I dont even know where to start as for implementing or integrating

I see the following apps in google play, claiming to have php server, mysql, etc.

https://play.google.com/store/apps/details?id=com.sylkat.apache

So I know there is possibility to run php files within android application.

What my idea is,

  • Have the php server in a webview application, Add php files to an app directory,
  • Configure webview to open the following URL "Localhost"
  • Webview application does not need requirement of MySQL, just simply process php.
  • Webview application does not need to worry about storage because no storage will be saved on it.

What I am NOT seeking for in this question

  • Using other apps in playstore, because this will be an independent application.
  • Being instructed to convert the files into other formats such as html, javascript, etc.
  • suggesting options not relevant to the question.

I am aware php is server sided code.

  • 2
    The statement "I am aware php is server sided code" vastly contradicts the rest of it... – Martin Zeitler May 15 '22 at 00:32
  • Im only stating that because somebody is going to comment that and its of no good use in the thread. – Valve Social May 15 '22 at 00:33
  • 1
    If you would have tried this package, or at least would have read the reviews, you'd realize how pointless this is. One probably could build PHP or Apache HTTPd for the underlying ARM64 Linux, but not the JVM; there's eg. NanoHTTPd which runs on JVM – Martin Zeitler May 15 '22 at 00:37
  • The main objective is to offload the rendering and processing from the server for mobile devices. This can reduce a ton of bandwith leaving it up to the mobile device with the server scripts. Have web server features, php files configured to use amazon cloud storage bucket, and remote sql. You dont even need a main server for php at this point. Thats not pointless at all, that sounds more like a smart idea. – Valve Social May 15 '22 at 00:45
  • @MartinZeitler i dont find it pointless when i believe your not getting the picture of why i put this post up. Your commenting to somebody thats runninng 16 servers for 3 web apps. Traffic can be high, something like this in testing would actually reduce a ton of bandwith and possibly create a door for unique opportunities. – Valve Social May 15 '22 at 02:42

1 Answers1

1

This is a list of challenges you face if you wish to run PHP code on a modern Android device.

I searched and found some projects implying that PHP can be run on Android

While I can't speak to any closed source projects, there are a few open source one, DroidPHP and more recent ones MyServer and lampTermux. But a bit of history/background is needed to understand what these projects represent.

PHP is written in C/C++. While Android does support C/C++ via the Android NDK, what's missing is that a PHP server expects to be run in a constant power Posix compliant environment which Android does not support out of the box.

The first one DroidPHP, which appears abandoned by the author, uses Busybox which provides a POSIX compatible environment but requires superuser/root permission which requires 'rooting' the Android device. Note that 'rooting' generally voids device warranties.

With billions of users over the years, the Android ecosystem has increased the security of each version reducing the attack surface for any bad-actor.

The other two github projects use Termux which provide a POSIX-like environment, which can be used with root and in a more limited fashion without root.

Hey that sounds great, so I can use Termux to run my PHP code.

A few caveats:

  1. Android manufacturers have added in their own battery saving processing resulting in a site like: https://dontkillmyapp.com/ if your app only runs in foreground you are probably safe.

  2. From the Termux repo README regarding Android 12:

NOTICE: Termux is broken on Android 12. Android OS will kill any (phantom) processes greater than 32 (limit is for all apps combined) and also kill any processes using excessive CPU.

  1. You'll need to host your own packages, if you intend to release a standalone app. From the Termux FAQ

Yes, as Termux is open-source and uses a GNU GPL v3.0 and in some components Apache-2.0 license, you can freely re-use existing components as soon as you met the license requirements.

However license does not cover "free" use of our hosting capabilities which are somewhat limited. You cannot use our package repositories in your own project(s). Please build packages and host them yourself.

Get started with information on developer's wiki pages: https://github.com/termux/termux-packages/wiki.

  1. Due to increased security restrictions Termux is no longer supported on the Google Play Store. So if the Android app is for commercial release, migrating your project to Java/Kotlin or even JavaScript in a WebView will allow for support in the Google Play Store, given that Termux (and its requirements for operation) is currently incompatible.

If you follow the embedded attempt issue thread you'll see that embedding is a involved process.

Sources: https://www.reddit.com/r/termux/comments/p3exkr/how_can_i_make_an_android_apk_app_based_on_termux/

Morrison Chang
  • 11,691
  • 3
  • 41
  • 77
  • thank you for the information, this may give me some direction to the project. But reading over most of it kind of gives me less hope. Other than seeing if i can do anything with Termux, – Valve Social May 15 '22 at 08:15
  • Also yes, app would be designed to be a foreground application. – Valve Social May 15 '22 at 08:16