Build PHP environment on gae and open URL rewrite

Source: Internet
Author: User
Tags filter copy php file resource

1. Download Quercus:

http://quercus.caucho.com/

Version of course the best of the latest, because in principle, the new version of PHP support is higher, but in their own testing when the latest 4.0.25 have a problem, and then swap 4.0.18 version.

Select a file download in the war format and use WinRAR decompression to copy the Web-inf\lib\ jar to the war\web-inf\lib\ directory under Gae project

2. Configure Quercus:

Configure support for PHP files in Appengine-web.xml:

    1. 		<static-files>
    2. <exclude path= "/**.php"/>
    3. </static-files>
    4. <resource-files>
    5. <include path= "/**.php"/>
    6. </resource-files>

Add a servlet to the Web.xml:

    1. 		<servlet>
    2. <servlet-name>quercus servlet</servlet-name>
    3. <servlet-class>com.caucho.quercus.servlet.GoogleQuercusServlet</servlet-class>
    4. </servlet>

To add a mapping to a PHP file:

    1. 		<servlet-mapping>
    2. <servlet-name>quercus servlet</servlet-name>
    3. <url-pattern>*.php</url-pattern>
    4. </servlet-mapping>

3. Implement URL rewriting (implemented by Urlrewritefilter):

Download the Urlrewritefilter and copy the Urlrewritefilter-*.jar to the War\web-inf\lib\ directory of the Project

Add URL filter to Web.xml

  1. 		<filter>
  2. <filter-name>UrlRewriteFilter</filter-name>
  3. <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
  4. </filter>
  5. <filter-mapping>
  6. <filter-name>UrlRewriteFilter</filter-name>
  7. <url-pattern>/*</url-pattern>
  8. <dispatcher>REQUEST</dispatcher>
  9. <dispatcher>FORWARD</dispatcher>
  10. </filter-mapping>

Create a new URL rewrite configuration file in the War\web-inf directory of the project: Urlrewrite.xml

  1. 		<?xml version= "1.0" encoding= "Utf-8"?>
  2. <! DOCTYPE urlrewrite Public "-//tuckey.org//dtd urlrewrite 4.0//en"
  3. "Http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd" >
  4. <urlrewrite>
  5. <rule enabled= "true" match-type= "regex" >
  6. <note>UrlRewrite</note>
  7. <condition type= "Request-filename" operator= "Notfile" name= "Notfile" next= "and"/>
  8. <condition type= "Request-filename" operator= "Notdir" name= "Notdir" next= "and"/>
  9. <from>/(. *) </from>
  10. <to last= "true" type= "forward" >/index.php</to>
  11. </rule>
  12. </urlrewrite>

This rule is equivalent to the one in. htaccess:

Rewritecond%{script_filename}!-f

Rewritecond%{script_filename}!-d

Rewriterule ^ (. *) $ index.php/$1

Note: This rule may cause gae local admin http://localhost:8888/_ah/admin/to fail because the time relationship is no longer fixed.

4. Test:

Create a new index.php file in the War\ directory of the project:

    1. 		<?php
    2. Echo ' <pre> ';
    3. Print_r ($_server);
    4. ?>

Because I have set index.php to welcome file, I open the http://localhost:8888/directly

The effect is as shown in the figure:

Some reference materials are attached:

http://blog.caucho.com/2009/04/28/quercus-on-the-google-app-engine/

http://blog.caucho.com/2009/05/31/quercus-on-google-app-engine/

http://tuckey.org/urlrewrite/#documentation

Phper are still hesitating, hurry up!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.