PHP server runs php code

I want to configure jetty to run PHP files, but have not been successful so far. I have Jetty WTP tools installed in my Eclipse IDE.

When I start the Jetty server. I got an 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) in my WebContent folder. I also downloaded this library and added it to the class path (Eclipse: build path and add an external jar). Now I do not know what I did wrong. I also compiled php with:

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

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, :

$ /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? , , ecxeptions, .

( maven!)

+3
3

, :

Im, -8.1.5.v20120716

  • extract jetty-distribution-8.1.5.v20120716.zip, , Jetty

  • , , , webapps/ , : Jetty/contexts, Jetty/contexts-available, Jetty/webapps

  • : 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

    Jetty/webapps/MYPROJECT/WEB-INFO/web.xml

    <?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

    <? php phpinfo();

  • php.ini cgi.force_redirect = 0
  • :

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

    java -jar start.jar

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

:

HTH

+2

org.eclipse.jetty.servlets.CGI

+1
source

Source: https://habr.com/ru/post/1794501/


All Articles