【问题标题】:Python SimpleHTTPServer with PHPPython SimpleHTTPServer 与 PHP
【发布时间】:2012-08-27 11:36:15
【问题描述】:

我使用了 python -m SimpleHTTPServer,但是 PHP 文件没有执行,而是被下载了。

我在旧的post 中听说过WPHP。但我不知道如何使用它。 我该如何使用它?

【问题讨论】:

    标签: php python


    【解决方案1】:

    Python Webserver 将您的 PHP 文件发送到浏览器的原因可能是因为它没有配置或无法处理 PHP 文件。见https://serverfault.com/questions/338394/how-to-run-php-with-simplehttpserver

    PHP 5.4 有一个built-in webserver。你可以像这样从命令行调用它:

    php [options] -S <addr>:<port> [-t docroot]
    

    示例

    C:\Users\Gordon>php -S 127.0.0.1:80 -t .
    PHP 5.4.0 Development Server started at Sun Sep 02 14:20:28 2012
    Listening on 127.0.0.1:80
    Document root is C:\Users\Gordon
    Press Ctrl-C to quit.
    

    请注意,如果您省略-t,PHP 将使用当前工作目录。

    【讨论】:

    • @Gordon 我正在尝试使用w3schools example,但没有任何显示。我在 OSX 中运行 php 行。知道有什么问题吗?
    • @geotheory 请定义“无”。文档根目录是否设置为您的文件所在的路径?
    • cd 到文件夹并运行 php -S 127.0.0.1:8000。在浏览器中打开http://localhost:8000/http://127.0.0.1:8000/ 时,该文件夹中的网页index.html(使用w3school 代码)为空白。但是,浏览器中确实会出现console.log 消息。
    • @geotheory 尝试在末尾不使用 .。但是,即使这样,您的文件在调用 index.html 时也不会被解析。它必须是 index.php。
    猜你喜欢
    • 2014-04-23
    • 2015-06-08
    • 2016-01-28
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 2021-10-31
    • 2015-09-23
    相关资源
    最近更新 更多