Bottle Web 服务器 - 如何提供 PHP 文件?
Bottle web server - how to serve PHP file?
我正在开发由其他人制作的使用 Bottle 路由的网络应用程序。我想创建一个简单的登录页面,需要一些 PHP。如果我 return PHP 页面作为 static_file,任何 HTML 将被执行,但 PHP 不会,原因很明显。我应该如何为 PHP 文件提供动态文件?
不工作:
@route('/login')
def serve():
return static_file('login.php', root='.')
为了服务器 PHP 文件,您需要在网络服务器上安装 PHP。此外,网络服务器需要配置为检测 PHP 文件并执行它们。
从 Python 提供 PHP 文件有点没用,不推荐。
我建议您花时间将此脚本从 PHP 翻译成 Python。
昨天我也想做同样的事情,但我得到的问题答案清楚地表明这要么不可能,要么极其困难。我想到了为 运行 和 PHP 内置服务器编写一个 python 小程序。注意:PHP 需要能够从命令行 运行 才能工作。
#Import the os package so that this code can run commands
import os
#Get the port that the user wants to host on
port = str(input("What port would you like to host on?"))
#Add wanted port to the command that hosts the php server
cmd = "php -S localhost:" + port
#Actually run the command to host php server
os.system(cmd)
#Now the PHP server will take over until you
#use ctrl + C to quit hosting
记住端口必须是4个数字。当您托管它时,您可以 return 您 运行 此代码所在的文件夹中的任何文件,只需在浏览器中键入即可。示例:
localhost:8080/login.php
Returns login.php(如果存在)在您请求的本地主机端口上。
我正在开发由其他人制作的使用 Bottle 路由的网络应用程序。我想创建一个简单的登录页面,需要一些 PHP。如果我 return PHP 页面作为 static_file,任何 HTML 将被执行,但 PHP 不会,原因很明显。我应该如何为 PHP 文件提供动态文件?
不工作:
@route('/login')
def serve():
return static_file('login.php', root='.')
为了服务器 PHP 文件,您需要在网络服务器上安装 PHP。此外,网络服务器需要配置为检测 PHP 文件并执行它们。
从 Python 提供 PHP 文件有点没用,不推荐。 我建议您花时间将此脚本从 PHP 翻译成 Python。
昨天我也想做同样的事情,但我得到的问题答案清楚地表明这要么不可能,要么极其困难。我想到了为 运行 和 PHP 内置服务器编写一个 python 小程序。注意:PHP 需要能够从命令行 运行 才能工作。
#Import the os package so that this code can run commands
import os
#Get the port that the user wants to host on
port = str(input("What port would you like to host on?"))
#Add wanted port to the command that hosts the php server
cmd = "php -S localhost:" + port
#Actually run the command to host php server
os.system(cmd)
#Now the PHP server will take over until you
#use ctrl + C to quit hosting
记住端口必须是4个数字。当您托管它时,您可以 return 您 运行 此代码所在的文件夹中的任何文件,只需在浏览器中键入即可。示例:
localhost:8080/login.php
Returns login.php(如果存在)在您请求的本地主机端口上。