【问题标题】:How can i run Single PHP File using apache-tomcat-6.0.18?如何使用 apache-tomcat-6.0.18 运行单个 PHP 文件?
【发布时间】:2011-02-07 08:37:51
【问题描述】:

我想使用 apache-tomcat-6.0.18 运行单个 php 文件

我的项目是 GWT 项目,服务器端是 java servlet

我将我的项目部署在 apache-tomcat-6.0.18/webapps/ 文件夹中的服务器上

所以请告诉我运行php文件的解决方案

【问题讨论】:

  • Tomcat 是为运行 servlet 而设计的,它们处理自己对 HTTP 请求的响应。 PHP 被设计为一个预处理器,它与像 Apache 这样的成熟的网络服务器一起运行,它自己处理请求。
  • 同意戴夫。你把事情搞混了。它可以从 java 中运行 PHP(如下面的帖子中所解释的),但你想远离它。运行 java servlet,或者完全运行 PHP,如 code.google.com/p/gwtphp 中所述,如果您也绝对需要 GWT。但是不要混合技术,这是不值得的。

标签: php apache gwt


【解决方案1】:

我们可以通过使用 JavaBridge..

来做到这一点

下载下面的jar文件(即从JavaBridge.war中提取jar)

JavaBridge.jar
php-script.jar
php-servlet.jar

并放入您的项目 lib 文件夹。然后在 web.xml 中键入以下条目

web.xml

<!-- the following 8 lines extend the servlet spec 2.2 "url-pattern" to handle PHP PATH_INFO: *.php/something?what=that. Remove them, if you don't need this feature. -->
    <filter>
        <filter-name>PhpCGIFilter</filter-name>
        <filter-class>php.java.servlet.PhpCGIFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PhpCGIFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- the following adds the JSR223 listener. Remove it if you don't want to use the JSR223 API -->
    <listener>
        <listener-class>php.java.servlet.ContextLoaderListener</listener-class>
    </listener>

    <!-- the back end for external (console, Apache/IIS-) PHP scripts; remove it if you don't need this -->
    <servlet>
        <servlet-name>PhpJavaServlet</servlet-name>
        <servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>
    </servlet>

    <!-- runs PHP scripts in this web app; remove it if you don't need this -->
    <servlet>
        <servlet-name>PhpCGIServlet</servlet-name>
        <servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>PhpJavaServlet</servlet-name>
        <url-pattern>*.phpjavabridge</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>PhpCGIServlet</servlet-name>
        <url-pattern>*.php</url-pattern>
    </servlet-mapping>

保存文件。重启tomcat服务器。现在php文件将在tomcat服务器下工作!

【讨论】:

    【解决方案2】:

    “www”文件夹存在于 IIS 服务器而不是 apache ... 在 apache tomcat 服务器而不是 "www" 中,存在 "Root" 文件夹 复制该根文件夹中所有需要的文件并访问这些文件

    安装任何服务器后,必须重新启动一次,否则结果无法预测... 非常感谢

    【讨论】:

      【解决方案3】:

      Use the PHP/Java Bridge。只要你的 PHP 是在 cgi 支持下编译的,它应该可以无缝运行。

      【讨论】:

        【解决方案4】:

        Quercus 有一个允许在 apache tomcat 或 glassfish 中运行 PHP 脚本的战争。有关分步指南,请查看this 文章

        【讨论】:

          【解决方案5】:

          你应该把你的 php 文件放在 apache 安装中的www 文件夹中,然后你可以像这样从浏览器访问该文件:

          http://localhost/your_file_name.php
          

          localhost 是大多数配置中的默认主机名。

          【讨论】:

          • 但是apache-tomcat-6.0.18安装目录中没有www这样的文件夹
          • 'httdocs'或public_html之类的,你需要在apache目录中搜索这些名称。
          • “Apache Tomcat”与“Apache”不同。一个是 servlet 主机,另一个是 Web 服务器。
          • 我正在使用 Apache Tomacat 并且没有名为 httdocs & public_html 的文件夹。它只包含 bin、conf、logs、webapps、lib、work 文件夹
          猜你喜欢
          • 2019-05-31
          • 1970-01-01
          • 2011-06-05
          • 1970-01-01
          • 2011-10-09
          • 2012-09-03
          • 2019-09-29
          • 1970-01-01
          相关资源
          最近更新 更多