如何从Android上的命令行通过lighttpd运行php-fpm?

问题描述 投票:-1回答:1

我有一个PHP fpm二进制文件,该文件是从apk的(PHPRunner.apk)资产文件夹中收集的。 php-fpm和lighttpd二进制文件位于/data/data/ua.naiksoftware.phprunner文件夹。

PHP二进制名称php-fpm_7_0_0_arm和lighttpd lighttpd。我正在尝试通过Android手机中的Terminal Emulator(不是termux)在lighttpd服务器上运行PHP。我已经尝试使用bash脚本(位于/ system / bin文件夹),如下所示

run_lighttpd:

#!/system/bin/sh

filePath="/data/data/ua.naiksoftware.phprunner"

echo "Executing lighttpd..."
$filePath/lighttpd \
    -f $filePath/lighttpd.conf \
    2>&1 & PID_LIGTTPD=$!

echo "lighttpd=$PID_LIGTTPD"

export PHP_FCGI_CHILDREN=4
export PHP_FCGI_MAX_REQUESTS=10000
export TMPDIR=$filePath/tmp

$filePath/php-fpm_7_0_0_arm \
    -c $filePath/php.ini \
    -y $filePath/fpm.conf \
    2>&1 & PID_PHP=$!

unset PHP_FCGI_CHILDREN
unset PHP_FCGI_MAX_REQUESTS

echo "PHP=$PID_PHP"

lighttpd.conf:

var.basedir = "/storage/emulated/0/Programming/"
var.serverdir = "/data/data/ua.naiksoftware.phprunner/"

server.port = 8080
server.document-root = "/storage/emulated/0/Programming"
server.errorlog = serverdir + "log/lighttpd.log"
dir-listing.activate = "enable"

index-file.names = ("index.php", "index.html", "index.htm", "home.php","home.html","home.htm", "default.html")

fastcgi.server = ( ".php" => 
    ((
            #"host" => "0.0.0.0",
            #"port" => 9000,
            #"bin-path" => serverdir + "php-fpm_7_0_0_arm",
            "socket" => serverdir + "tmp/php-fpm.sock",
            "broken-scriptfilename" => "enable"
    ))
)


status.status-url                          = "/server-status"
status.config-url                          = "/server-config"

server.pid-file                            = serverdir + "tmp/lighttpd.pid"

mimetype.use-xattr        = "disable"
mimetype.assign             = (
  ".appcache"     =>      "text/cache-manifest",    
  ".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",
  ".class"        =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".tar.gz"       =>      "application/x-tgz",
  ".tgz"          =>      "application/x-tgz",
  ".tar"          =>      "application/x-tar",
  ".zip"          =>      "application/zip",
  ".mp3"          =>      "audio/mpeg",
  ".m3u"          =>      "audio/x-mpegurl",
  ".wma"          =>      "audio/x-ms-wma",
  ".wax"          =>      "audio/x-ms-wax",
  ".ogg"          =>      "application/ogg",
  ".wav"          =>      "audio/x-wav",
  ".gif"          =>      "image/gif",
  ".jpg"          =>      "image/jpeg",
  ".jpeg"         =>      "image/jpeg",
  ".png"          =>      "image/png",
  ".xbm"          =>      "image/x-xbitmap",
  ".xpm"          =>      "image/x-xpixmap",
  ".xwd"          =>      "image/x-xwindowdump",
  ".css"          =>      "text/css",
  ".html"         =>      "text/html",
  ".htm"          =>      "text/html",
  ".js"           =>      "text/javascript",
  ".asc"          =>      "text/plain",
  ".c"            =>      "text/plain",
  ".cpp"          =>      "text/plain",
  ".log"          =>      "text/plain",
  ".conf"         =>      "text/plain",
  ".text"         =>      "text/plain",
  ".txt"          =>      "text/plain",
  ".spec"         =>      "text/plain",
  ".dtd"          =>      "text/xml",
  ".xml"          =>      "text/xml",
  ".mpeg"         =>      "video/mpeg",
  ".mpg"          =>      "video/mpeg",
  ".mov"          =>      "video/quicktime",
  ".qt"           =>      "video/quicktime",
  ".avi"          =>      "video/x-msvideo",
  ".asf"          =>      "video/x-ms-asf",
  ".asx"          =>      "video/x-ms-asf",
  ".wmv"          =>      "video/x-ms-wmv",
  ".bz2"          =>      "application/x-bzip",
  ".tbz"          =>      "application/x-bzip-compressed-tar",
  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",
  ".odt"          =>      "application/vnd.oasis.opendocument.text",
  ".ods"          =>      "application/vnd.oasis.opendocument.spreadsheet",
  ".odp"          =>      "application/vnd.oasis.opendocument.presentation",
  ".odg"          =>      "application/vnd.oasis.opendocument.graphics",
  ".odc"          =>      "application/vnd.oasis.opendocument.chart",
  ".odf"          =>      "application/vnd.oasis.opendocument.formula",
  ".odi"          =>      "application/vnd.oasis.opendocument.image",
  ".odm"          =>      "application/vnd.oasis.opendocument.text-master",
  ".ott"          =>      "application/vnd.oasis.opendocument.text-template",
  ".ots"          =>      "application/vnd.oasis.opendocument.spreadsheet-template",
  ".otp"          =>      "application/vnd.oasis.opendocument.presentation-template",
  ".otg"          =>      "application/vnd.oasis.opendocument.graphics-template",
  ".otc"          =>      "application/vnd.oasis.opendocument.chart-template",
  ".otf"          =>      "application/vnd.oasis.opendocument.formula-template",
  ".oti"          =>      "application/vnd.oasis.opendocument.image-template",
  ".oth"          =>      "application/vnd.oasis.opendocument.text-web",

# make the default mime type application/octet-stream.
  ""              =>      "application/octet-stream",
)

server.max-request-size = 1000000
server.network-backend = "writev"
server.upload-dirs =( serverdir + "tmp" )

server.modules   = ( "mod_rewrite",
                     "mod_redirect",
                     "mod_alias",
                     "mod_extforward",
                     "mod_access",
                     "mod_auth",
                     "mod_setenv",
                     "mod_magnet",
                     "mod_flv_streaming",
                     "mod_indexfile",
                     "mod_userdir",
                     "mod_dirlisting",
                     "mod_status",
                     "mod_simple_vhost",
                     "mod_evhost",
                     "mod_secdownload",
                     "mod_cgi",
                     "mod_fastcgi",
                     "mod_scgi",
                     "mod_ssi",
                     "mod_proxy",
                     "mod_staticfile",
                     "mod_cml",
                     "mod_trigger_b4_dl",
                     "mod_webdav",
                     "mod_evasive",
                     "mod_compress",
                     "mod_usertrack",
                     "mod_expire",
                     "mod_accesslog"
)

fpm.conf文件内容太长。因此,下面仅包括重要部分。fpm.conf:

[global]
pid = /data/data/ua.naiksoftware.phprunner/tmp/php-fpm.pid
error_log = /data/data/ua.naiksoftware.phprunner/tmp/fpm.log
;syslog.facility = daemon
;syslog.ident = php-fpm
log_level = error

[www]
user = root
group = root
listen = /data/data/ua.naiksoftware.phprunner/tmp/php-fpm.sock
;listen = 0.0.0.0:9000
;listen.owner = @php_fpm_user@
;listen.group = @php_fpm_group@
;listen.mode = 0666
pm = dynamic
pm.max_children = 4
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

当我从终端运行(以root用户身份)run_lighttpd时,lighttpd正常运行,但是php无法运行,并返回如下所示的错误

root@iris702:/ # [07-Dec-2019 10:23:57] ERROR: [pool www] cannot get uid for user 'root'
root@iris702:/ # [07-Dec-2019 10:23:57] ERROR: FPM initialization failed

现在我的问题是:使用终端模拟器在没有任何问题的情况下将php-fpm(7.0)的lighttpd运行到我的Android手机(android 6.0)上的localhost中的最佳方法是什么?

note:

  • 我是root用户。
  • Android版本:6.0
  • php-fpm版本:PHP 7.0.0(fpm-fcgi)
  • lighttpd版本:1.4.35
  • PHPRunner.apk可以完美运行lighttpd和PHP。但我不想使用这个apk。
  • 所有文件位于:/data/data/ua.naiksoftware.phprunner

希望我的问题对您清楚。如果您需要更多信息,我将尝试再次解释。对不起,我的英语不好。

php android bash localhost lighttpd
1个回答
0
投票

您可以尝试使用chroot,如果有帮助。 Debian Chroot Page您可以安装chroot,因为您是root用户。因此,如果有帮助,您可以在chroot中将其apt-get。那应该工作。试试吧。只需运行以下命令(尽管对其进行编辑,以便它们可以正常工作):另外,如果您至少可以更新到android 7,请告诉我。

sudo debootstrap --arch=armhf --variant=minbase --foreign  wheezy  /media/PHONE\ CARD/debian  http://httpredir.debian.org/debian

如果不起作用,请尝试使用Lineage OS。我自己使用它,并会推荐它。它解决了我的大多数问题,不使用库存Android。

© www.soinside.com 2019 - 2024. All rights reserved.