码头服务器运行php代码 [英] jetty server run php code

查看:98
本文介绍了码头服务器运行php代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进行配置,以使jetty运行PHP文件,但到目前为止仍未成功.我在Eclipse IDE中安装了Jetty WTP工具.

I want to configure so that jetty runs PHP files, but have been unsuccessful so far. I have Jetty WTP tools installed in my Eclipse IDE.

当我启动Jetty服务器时.我遇到了例外: java.lang.ClassNotFoundException org.mortbay.servlet.CGI:org.mortbay.servlet.CGI javax.servlet.UnavailableException:org.mortbay.servlet.CGI .我在WebContent文件夹下放置了一个简单的php文件(index.php).我还下载了此并将其添加到类路径(Eclipse:build路径并添加外部jar).我现在不知道我做错了什么.我还用以下命令编译了php:

When I start up the Jetty server. I got the exception: java.lang.ClassNotFoundException org.mortbay.servlet.CGI: org.mortbay.servlet.CGI and javax.servlet.UnavailableException: org.mortbay.servlet.CGI. I put a simple php file(index.php) under my WebContent folder. I also downloaded this library and added it to the classpath(Eclipse: build path and add external jar). I have no clue now what I've done wrong. I also compiled php with:

./configure --with-fastcgi=/usr/local
make
sudo make install

我的web.xml文件如下所示:

And my web.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Sample PHP Application</display-name>
    <servlet>
        <servlet-name>PHP</servlet-name>  
        <servlet-class>org.mortbay.servlet.CGI</servlet-class>
        <init-param>
            <param-name>commandPrefix</param-name>
            <param-value>/usr/local/bin/php-cgi-fix</param-value>
        </init-param>
    </servlet>

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

    <welcome-file-list>
        <welcome-file>index.php</welcome-file>
    </welcome-file-list>
</web-app>

这可能是我的php-cgi-fix文件,当我打开它时,我在终端收到了Followig文本:

It could be my php-cgi-fix file, I got the followig text i terminal when i open it:

$ /usr/local/bin/php-cgi-fix ; exit;
/usr/local/bin/php-cgi-fix: line 3: /usr/bin/php-cgi: No such file or directory
logout

应该不是/usr/local/php-cgi吗?好的,我现在尝试了一下,但是启动服务器时仍然得到相同的结果.

Shouldn't be /usr/local/php-cgi instead? Ok I tried that now, but still I got the same ecxeptions when I launch the server.

(我真的也不喜欢使用maven!)

(I really don't like to use maven too!)

推荐答案

以下是我为使其运行而要做的事情:

Here's what i did to get it running:

我使用码头分布8.1.5.v20120716

Im using jetty-distribution-8.1.5.v20120716

  • 解压缩jetty-distribution-8.1.5.v20120716.zip,让我们说一个目录Jetty

  • extract jetty-distribution-8.1.5.v20120716.zip to let's say a directory Jetty

我认为这不是必需的,但是我不希望其他webapps/servlet干扰配置,因此:清空目录Jetty/contexts,Jetty/contexts-available,Jetty/webapps

i don't think this is necessary, but i didn't want other webapps/servlets to interfere the configuration, so: empty the directories Jetty/contexts, Jetty/contexts-available, Jetty/webapps

可选:要获取调试消息,请在Jetty/etc/jetty.xml中添加以下内容

optional: to get debugging messages add the following in Jetty/etc/jetty.xml


    <Get class="org.eclipse.jetty.util.log.Log" name="log">
      <Call name="setDebugEnabled">
        <Arg type="boolean">true</Arg>
      </Call>
    </Get>

  • 使用内容创建文件Jetty/bin/php5-cgi-fix.sh
  • 
        #!/usr/bin/bash
        export SCRIPT_FILENAME=$1
        /usr/bin/php5-cgi
    

    • 创建以下目录:Jetty/webapps/MYPROJECT,Jetty/webapps/MYPROJECT/WEB-INF,Jetty/webapps/MYPROJECT/cgi-bin

      • create the following directories: Jetty/webapps/MYPROJECT, Jetty/webapps/MYPROJECT/WEB-INF, Jetty/webapps/MYPROJECT/cgi-bin

        Jetty/webapps/MYPROJECT/WEB-INFO/web.xml的内容为

        the content of Jetty/webapps/MYPROJECT/WEB-INFO/web.xml is

        
            <?xml version="1.0" encoding="ISO-8859-1"?>
            <web-app
              xmlns="http://java.sun.com/xml/ns/j2ee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
              version="2.4"
            >
        
             <display-name>MYPROJECT</display-name>
        
             <servlet>
               <servlet-name>PHP</servlet-name>
               <servlet-class>org.eclipse.jetty.servlets.CGI</servlet-class>
               <load-on-startup>1</load-on-startup>
        
               <init-param>
                    <param-name>commandPrefix</param-name>
                    <param-value>../../../bin/php5-cgi-fix.sh</param-value>
               </init-param>
        
                  <init-param>
                      <param-name>Path</param-name>
                      <param-value>/bin:/usr/bin:/usr/local/bin</param-value>
                  </init-param>
                  <init-param>
                      <param-name>cgibinResourceBase</param-name>
                      <param-value>webapps/MYPROJECT</param-value>
                  </init-param>
        
            <!--
                  <init-param>
                      <param-name>cgibinResourceBaseIsRelative</param-name>
                      <param-value>true</param-value>
                  </init-param>
            -->
            <!--
               <init-param>
                    <param-name>ENV_yourRequiredEnvironmentVariable</param-name>
                    <param-value>yourValue</param-value>
               </init-param>
            -->
               <!-- Path, other ENV_variables including ENV_SystemRoot, ENV_REDIRECT_STATUS on Windows -->
             </servlet>
        
             <servlet-mapping>
               <servlet-name>PHP</servlet-name>
               <url-pattern>*.php</url-pattern>
               <!-- Any other URL patterns that are needed by your app to be processed by PHP -->
             </servlet-mapping>
        
             <!-- If you want http://yourhost/yourapp to call yourapp/yourapp.php then make a welcome file -->
            <!--
             <welcome-file-list>
               <welcome-file>index.php</welcome-file>
             </welcome-file-list>
            -->
            </web-app>
        

        • 创建一个包含内容的php文件,如Jetty/webapps/MYPROJECT/cgi-bin/test.php

          • create a php file like Jetty/webapps/MYPROJECT/cgi-bin/test.php with content

            <?php phpinfo();

            <?php phpinfo();

            逃生码头:

            java -Dorg.eclipse.jetty.servlets.CGI.LEVEL = DEBUG -jar start.jar etc/jetty-requestlog.xml

            java -Dorg.eclipse.jetty.servlets.CGI.LEVEL=DEBUG -jar start.jar etc/jetty-requestlog.xml

            OR

            java -jar start.jar

            java -jar start.jar

            http://localhost:8080/MYPROJECT/cgi-bin/test.php

          • 提示:

            • ,如果您尝试通过以下方式在Windows上使用此功能: php5-cgi-fix.bat文件,您必须像这样更改web.xml配置中的命令前缀:

            • in case you try to use this on windows via e.g. php5-cgi-fix.bat file you have to change the command prefix in web.xml config like this:

            cmd.exe/c ../../../bin/php5-cgi-fix.bat

            cmd.exe /c ../../../bin/php5-cgi-fix.bat

            jetty源. //repo1.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/ 其中org/eclipse/jetty/servlets/CGI.java是执行php脚本的cgi servlets代码

            jetty source can be obtained from http://repo1.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/ where org/eclipse/jetty/servlets/CGI.java is the cgi servlets code which executes the php scripts

            hth

            这篇关于码头服务器运行php代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆