1. CGI support in Jetty The Jetty brings an CGI servlets out of the box. The servlet class is org.eclipse.jetty.servlets.CGI and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:

`#

Enable optional servlets module

#
–module=servlets`

  1. WordPress The Fedora distribution does package WordPress for easy installation and upgrade via it’s package manager. WordPress is installed in /usr/share/wordpress.

  2. WordPress as Java webapp To make WordPress available as CGI webapp a web.xml must be deployed to the Jetty server.

  • Create directory wordpress in jetty/webapps/
  • Create directory WEB-INF in the newly created webapp directory jetty/webapps/wordpress/
  • Create deployment descriptor web.xml
  1. Deployment descriptor The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.
  • org.eclipse.jetty.servlets.CGI – Handles all incoming *.php request
  • org.eclipse.jetty.servlet.DefaultServlet – Handles all other/static requests
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
      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/webapp_2_5.xsd">
    <display-name>Wordpress</display-name>
    <servlet>
        <servlet-name>cgi-servlet</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlets.CGI</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>commandPrefix</param-name>
            <param-value>/usr/bin/php-cgi-fix</param-value>
        </init-param>
        <init-param>
            <param-name>ignoreExitState</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_REDIRECT_STATUS</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>cgibinResourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_PHP_DOCUMENT_ROOT</param-name>
            <param-value>/usr/share/wordpress/</param-value>
        </init-param>
    </servlet>


    <servlet>
        <servlet-name>default</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>dirAllowed</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
    </servlet>

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

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.php</welcome-file>
    </welcome-file-list>
</web-app>
  1. PHP-CGI Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php which is the path relative to the webapps context path.

The exec call of the php-cgi is done correctly: /usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php but the first argument is ignored by the php-cgi, when compiled with the force_redirect option (see php-src/sapi/cgi/cgi_main.c).

As the script in the environment variable SCRIPT_FILENAME is executed by php-cgi program, a littel wrapper must be provided.

  • Create /usr/bin/php-cgi-fix
  • Make the script executable with chmod +x
  • /usr/bin/php-cgi-fix content: `1. CGI support in Jetty The [Jetty][1] brings an CGI servlets out of the box. The servlet class isorg.eclipse.jetty.servlets.CGI` and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:

`#

Enable optional servlets module

#
–module=servlets`

  1. WordPress The Fedora distribution does package WordPress for easy installation and upgrade via it’s package manager. WordPress is installed in /usr/share/wordpress.

  2. WordPress as Java webapp To make WordPress available as CGI webapp a web.xml must be deployed to the Jetty server.

  • Create directory wordpress in jetty/webapps/
  • Create directory WEB-INF in the newly created webapp directory jetty/webapps/wordpress/
  • Create deployment descriptor web.xml
  1. Deployment descriptor The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.
  • org.eclipse.jetty.servlets.CGI – Handles all incoming *.php request
  • org.eclipse.jetty.servlet.DefaultServlet – Handles all other/static requests
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
      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/webapp_2_5.xsd">
    <display-name>Wordpress</display-name>
    <servlet>
        <servlet-name>cgi-servlet</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlets.CGI</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>commandPrefix</param-name>
            <param-value>/usr/bin/php-cgi-fix</param-value>
        </init-param>
        <init-param>
            <param-name>ignoreExitState</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_REDIRECT_STATUS</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>cgibinResourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_PHP_DOCUMENT_ROOT</param-name>
            <param-value>/usr/share/wordpress/</param-value>
        </init-param>
    </servlet>


    <servlet>
        <servlet-name>default</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>dirAllowed</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
    </servlet>

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

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.php</welcome-file>
    </welcome-file-list>
</web-app>
  1. PHP-CGI Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php which is the path relative to the webapps context path.

The exec call of the php-cgi is done correctly: /usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php but the first argument is ignored by the php-cgi, when compiled with the force_redirect option (see php-src/sapi/cgi/cgi_main.c).

As the script in the environment variable SCRIPT_FILENAME is executed by php-cgi program, a littel wrapper must be provided.

  • Create /usr/bin/php-cgi-fix
  • Make the script executable with chmod +x
  • /usr/bin/php-cgi-fix content: ``

Above script takes the correct path relative to the wordpress installation directory and overwrites the SCRIPT_FILENAME environment variable.

  • Debugging CGI servlet calls Debug output of the CGI servlet can be activated by adding the following entry to jetty/resources/jetty-logging.properties:

``1. CGI support in Jetty The [Jetty][1] brings an CGI servlets out of the box. The servlet class isorg.eclipse.jetty.servlets.CGI` and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:

`#

Enable optional servlets module

#
–module=servlets`

  1. WordPress The Fedora distribution does package WordPress for easy installation and upgrade via it’s package manager. WordPress is installed in /usr/share/wordpress.

  2. WordPress as Java webapp To make WordPress available as CGI webapp a web.xml must be deployed to the Jetty server.

  • Create directory wordpress in jetty/webapps/
  • Create directory WEB-INF in the newly created webapp directory jetty/webapps/wordpress/
  • Create deployment descriptor web.xml
  1. Deployment descriptor The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.
  • org.eclipse.jetty.servlets.CGI – Handles all incoming *.php request
  • org.eclipse.jetty.servlet.DefaultServlet – Handles all other/static requests
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
      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/webapp_2_5.xsd">
    <display-name>Wordpress</display-name>
    <servlet>
        <servlet-name>cgi-servlet</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlets.CGI</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>commandPrefix</param-name>
            <param-value>/usr/bin/php-cgi-fix</param-value>
        </init-param>
        <init-param>
            <param-name>ignoreExitState</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_REDIRECT_STATUS</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>cgibinResourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_PHP_DOCUMENT_ROOT</param-name>
            <param-value>/usr/share/wordpress/</param-value>
        </init-param>
    </servlet>


    <servlet>
        <servlet-name>default</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>dirAllowed</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
    </servlet>

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

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.php</welcome-file>
    </welcome-file-list>
</web-app>
  1. PHP-CGI Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php which is the path relative to the webapps context path.

The exec call of the php-cgi is done correctly: /usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php but the first argument is ignored by the php-cgi, when compiled with the force_redirect option (see php-src/sapi/cgi/cgi_main.c).

As the script in the environment variable SCRIPT_FILENAME is executed by php-cgi program, a littel wrapper must be provided.

  • Create /usr/bin/php-cgi-fix
  • Make the script executable with chmod +x
  • /usr/bin/php-cgi-fix content: `1. CGI support in Jetty The [Jetty][1] brings an CGI servlets out of the box. The servlet class isorg.eclipse.jetty.servlets.CGI` and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:

`#

Enable optional servlets module

#
–module=servlets`

  1. WordPress The Fedora distribution does package WordPress for easy installation and upgrade via it’s package manager. WordPress is installed in /usr/share/wordpress.

  2. WordPress as Java webapp To make WordPress available as CGI webapp a web.xml must be deployed to the Jetty server.

  • Create directory wordpress in jetty/webapps/
  • Create directory WEB-INF in the newly created webapp directory jetty/webapps/wordpress/
  • Create deployment descriptor web.xml
  1. Deployment descriptor The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.
  • org.eclipse.jetty.servlets.CGI – Handles all incoming *.php request
  • org.eclipse.jetty.servlet.DefaultServlet – Handles all other/static requests
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
      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/webapp_2_5.xsd">
    <display-name>Wordpress</display-name>
    <servlet>
        <servlet-name>cgi-servlet</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlets.CGI</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>commandPrefix</param-name>
            <param-value>/usr/bin/php-cgi-fix</param-value>
        </init-param>
        <init-param>
            <param-name>ignoreExitState</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_REDIRECT_STATUS</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>cgibinResourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>ENV_PHP_DOCUMENT_ROOT</param-name>
            <param-value>/usr/share/wordpress/</param-value>
        </init-param>
    </servlet>


    <servlet>
        <servlet-name>default</servlet-name>  
        <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>dirAllowed</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
        <init-param>
            <param-name>resourceBase</param-name>
            <param-value>/usr/share/wordpress</param-value>
        </init-param>
    </servlet>

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

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.php</welcome-file>
    </welcome-file-list>
</web-app>
  1. PHP-CGI Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php which is the path relative to the webapps context path.

The exec call of the php-cgi is done correctly: /usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php but the first argument is ignored by the php-cgi, when compiled with the force_redirect option (see php-src/sapi/cgi/cgi_main.c).

As the script in the environment variable SCRIPT_FILENAME is executed by php-cgi program, a littel wrapper must be provided.

  • Create /usr/bin/php-cgi-fix
  • Make the script executable with chmod +x
  • /usr/bin/php-cgi-fix content: ``

Above script takes the correct path relative to the wordpress installation directory and overwrites the SCRIPT_FILENAME environment variable.

  • Debugging CGI servlet calls Debug output of the CGI servlet can be activated by adding the following entry to jetty/resources/jetty-logging.properties:

  * Unsovled wordpress/index.php problem
WordPress now nearly works correctly, but when trying to access the `wordpress/index.php` file, the result is:

````  1. CGI support in Jetty
The [Jetty][1] brings an CGI servlets out of the box. The servlet class is `org.eclipse.jetty.servlets.CGI` and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:
  
`#<br />
# Enable optional servlets module<br />
#<br />
--module=servlets`

  2. WordPress
The Fedora distribution does package WordPress for easy installation and upgrade via it&#8217;s package manager. WordPress is installed in `/usr/share/wordpress`.

  3. WordPress as Java webapp
To make WordPress available as CGI webapp a `web.xml` must be deployed to the Jetty server.

  * Create directory `wordpress` in `jetty/webapps/`
  * Create directory `WEB-INF` in the newly created webapp directory `jetty/webapps/wordpress/`
  * Create deployment descriptor `web.xml` 

  4. Deployment descriptor
The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.

  * org.eclipse.jetty.servlets.CGI &#8211; Handles all incoming *.php request
  * org.eclipse.jetty.servlet.DefaultServlet &#8211; Handles all other/static requests

<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app version="3.0"
      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/webapp_2_5.xsd"&gt;
    &lt;display-name&gt;Wordpress&lt;/display-name&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlets.CGI&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;commandPrefix&lt;/param-name&gt;
            &lt;param-value&gt;/usr/bin/php-cgi-fix&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ignoreExitState&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_REDIRECT_STATUS&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;cgibinResourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_PHP_DOCUMENT_ROOT&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress/&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;


    &lt;servlet&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlet.DefaultServlet&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;dirAllowed&lt;/param-name&gt;
            &lt;param-value&gt;false&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.php&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.php&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;</pre>

  5. PHP-CGI
Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to `SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php` which is the path relative to the webapps context path.
  
The exec call of the php-cgi is done correctly: `/usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php` but the first argument is ignored by the php-cgi, when compiled with the `force_redirect` option (see `php-src/sapi/cgi/cgi_main.c`).
  
As the script in the environment variable `SCRIPT_FILENAME` is executed by php-cgi program, a littel wrapper must be provided.

  * Create `/usr/bin/php-cgi-fix`
  * Make the script executable with `chmod +x`
  * /usr/bin/php-cgi-fix content:
``  1. CGI support in Jetty
The [Jetty][1] brings an CGI servlets out of the box. The servlet class is `org.eclipse.jetty.servlets.CGI` and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:
  
`#<br />
# Enable optional servlets module<br />
#<br />
--module=servlets`

  2. WordPress
The Fedora distribution does package WordPress for easy installation and upgrade via it&#8217;s package manager. WordPress is installed in `/usr/share/wordpress`.

  3. WordPress as Java webapp
To make WordPress available as CGI webapp a `web.xml` must be deployed to the Jetty server.

  * Create directory `wordpress` in `jetty/webapps/`
  * Create directory `WEB-INF` in the newly created webapp directory `jetty/webapps/wordpress/`
  * Create deployment descriptor `web.xml` 

  4. Deployment descriptor
The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.

  * org.eclipse.jetty.servlets.CGI &#8211; Handles all incoming *.php request
  * org.eclipse.jetty.servlet.DefaultServlet &#8211; Handles all other/static requests

<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app version="3.0"
      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/webapp_2_5.xsd"&gt;
    &lt;display-name&gt;Wordpress&lt;/display-name&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlets.CGI&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;commandPrefix&lt;/param-name&gt;
            &lt;param-value&gt;/usr/bin/php-cgi-fix&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ignoreExitState&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_REDIRECT_STATUS&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;cgibinResourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_PHP_DOCUMENT_ROOT&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress/&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;


    &lt;servlet&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlet.DefaultServlet&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;dirAllowed&lt;/param-name&gt;
            &lt;param-value&gt;false&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.php&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.php&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;</pre>

  5. PHP-CGI
Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to `SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php` which is the path relative to the webapps context path.
  
The exec call of the php-cgi is done correctly: `/usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php` but the first argument is ignored by the php-cgi, when compiled with the `force_redirect` option (see `php-src/sapi/cgi/cgi_main.c`).
  
As the script in the environment variable `SCRIPT_FILENAME` is executed by php-cgi program, a littel wrapper must be provided.

  * Create `/usr/bin/php-cgi-fix`
  * Make the script executable with `chmod +x`
  * /usr/bin/php-cgi-fix content:
`` </ul> 

Above script takes the correct path relative to the wordpress installation directory and overwrites the SCRIPT_FILENAME environment variable.

  * Debugging CGI servlet calls
Debug output of the CGI servlet can be activated by adding the following entry to `jetty/resources/jetty-logging.properties`:
  
```  1. CGI support in Jetty
The [Jetty][1] brings an CGI servlets out of the box. The servlet class is `org.eclipse.jetty.servlets.CGI` and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:
  
`#<br />
# Enable optional servlets module<br />
#<br />
--module=servlets`

  2. WordPress
The Fedora distribution does package WordPress for easy installation and upgrade via it&#8217;s package manager. WordPress is installed in `/usr/share/wordpress`.

  3. WordPress as Java webapp
To make WordPress available as CGI webapp a `web.xml` must be deployed to the Jetty server.

  * Create directory `wordpress` in `jetty/webapps/`
  * Create directory `WEB-INF` in the newly created webapp directory `jetty/webapps/wordpress/`
  * Create deployment descriptor `web.xml` 

  4. Deployment descriptor
The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.

  * org.eclipse.jetty.servlets.CGI &#8211; Handles all incoming *.php request
  * org.eclipse.jetty.servlet.DefaultServlet &#8211; Handles all other/static requests

<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app version="3.0"
      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/webapp_2_5.xsd"&gt;
    &lt;display-name&gt;Wordpress&lt;/display-name&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlets.CGI&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;commandPrefix&lt;/param-name&gt;
            &lt;param-value&gt;/usr/bin/php-cgi-fix&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ignoreExitState&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_REDIRECT_STATUS&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;cgibinResourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_PHP_DOCUMENT_ROOT&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress/&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;


    &lt;servlet&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlet.DefaultServlet&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;dirAllowed&lt;/param-name&gt;
            &lt;param-value&gt;false&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.php&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.php&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;</pre>

  5. PHP-CGI
Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to `SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php` which is the path relative to the webapps context path.
  
The exec call of the php-cgi is done correctly: `/usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php` but the first argument is ignored by the php-cgi, when compiled with the `force_redirect` option (see `php-src/sapi/cgi/cgi_main.c`).
  
As the script in the environment variable `SCRIPT_FILENAME` is executed by php-cgi program, a littel wrapper must be provided.

  * Create `/usr/bin/php-cgi-fix`
  * Make the script executable with `chmod +x`
  * /usr/bin/php-cgi-fix content:
``  1. CGI support in Jetty
The [Jetty][1] brings an CGI servlets out of the box. The servlet class is `org.eclipse.jetty.servlets.CGI` and is contained in the jetty-servlets module. To make this class generally available in jetty it must be added in the start.ini file of jetty:
  
`#<br />
# Enable optional servlets module<br />
#<br />
--module=servlets`

  2. WordPress
The Fedora distribution does package WordPress for easy installation and upgrade via it&#8217;s package manager. WordPress is installed in `/usr/share/wordpress`.

  3. WordPress as Java webapp
To make WordPress available as CGI webapp a `web.xml` must be deployed to the Jetty server.

  * Create directory `wordpress` in `jetty/webapps/`
  * Create directory `WEB-INF` in the newly created webapp directory `jetty/webapps/wordpress/`
  * Create deployment descriptor `web.xml` 

  4. Deployment descriptor
The following deployment descriptor uses two servelts to process incoming HTTP request and fordword the php request to the PHP CGI script.

  * org.eclipse.jetty.servlets.CGI &#8211; Handles all incoming *.php request
  * org.eclipse.jetty.servlet.DefaultServlet &#8211; Handles all other/static requests

<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app version="3.0"
      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/webapp_2_5.xsd"&gt;
    &lt;display-name&gt;Wordpress&lt;/display-name&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlets.CGI&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;commandPrefix&lt;/param-name&gt;
            &lt;param-value&gt;/usr/bin/php-cgi-fix&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ignoreExitState&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_REDIRECT_STATUS&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;cgibinResourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;ENV_PHP_DOCUMENT_ROOT&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress/&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;


    &lt;servlet&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;  
        &lt;servlet-class&gt;org.eclipse.jetty.servlet.DefaultServlet&lt;/servlet-class&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;dirAllowed&lt;/param-name&gt;
            &lt;param-value&gt;false&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;resourceBase&lt;/param-name&gt;
            &lt;param-value&gt;/usr/share/wordpress&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;cgi-servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.php&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;default&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.php&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;</pre>

  5. PHP-CGI
Sadly with above deployment descriptor the CGI servlet sets the environment variable for the php-cgi program to `SCRIPT_FILENAME=/opt/jetty-distribution-9.1.0.v20131115/webapps/wordpress/wordpress/wp-admin/admin-ajax.php` which is the path relative to the webapps context path.
  
The exec call of the php-cgi is done correctly: `/usr/bin/php-cgi-fix /usr/share/wordpress/wp-admin/admin-ajax.php` but the first argument is ignored by the php-cgi, when compiled with the `force_redirect` option (see `php-src/sapi/cgi/cgi_main.c`).
  
As the script in the environment variable `SCRIPT_FILENAME` is executed by php-cgi program, a littel wrapper must be provided.

  * Create `/usr/bin/php-cgi-fix`
  * Make the script executable with `chmod +x`
  * /usr/bin/php-cgi-fix content:
`` </ul> 

Above script takes the correct path relative to the wordpress installation directory and overwrites the SCRIPT_FILENAME environment variable.

  * Debugging CGI servlet calls
Debug output of the CGI servlet can be activated by adding the following entry to `jetty/resources/jetty-logging.properties`:
  
  • Unsovled wordpress/index.php problem WordPress now nearly works correctly, but when trying to access the wordpress/index.php file, the result is:

````

[UPDATE]

This redirect is done in wordpress/wp-includes/canonical.php line 455 for some reasons I didn’t find out yet, but I guess has to do with some check against the installation path wordpress thinks it is installed in and the real URL path.

This blog entry describes how to disable the WordPress Canonical URL.

Another solution is to uncomment this line /* add_action('template_redirect', 'redirect_canonical'); */ in the file wp-includes/canonical.php. This makes wordpress work with a given context path.