1.下載quercus:
http://quercus.caucho.com/
版本當然最新的最好,因為原則上來說新版本對php支援程度更高,但是在自己測試的時候發現最新的4.0.25存在一點問題,於是換用4.0.18版本.
選擇WAR格式的檔案下載,利用Winrar解壓,將WEB-INFlib的jar拷貝至GAE工程下的warWEB-INFlib目錄
2.配置Quercus:
在appengine-web.xml中配置對php檔案的支援:
- <static-files>
- <exclude path="/**.php" />
- static-files>
- <resource-files>
- <include path="/**.php" />
- resource-files>
在web.xml中添加一個servlet:
- <servlet>
- <servlet-name>Quercus Servletservlet-name>
- <servlet-class>com.caucho.quercus.servlet.GoogleQuercusServletservlet-class>
- servlet>
添加對php檔案的映射:
- <servlet-mapping>
- <servlet-name>Quercus Servletservlet-name>
- <url-pattern>*.phpurl-pattern>
- servlet-mapping>
3.實現URL重寫(通過UrlRewriteFilter實現):
下載UrlRewriteFilter,將urlrewritefilter-*.jar拷貝在工程的warWEB-INFlib目錄下
在web.xml中添加URL過濾
- <filter>
- <filter-name>UrlRewriteFilterfilter-name>
- <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilterfilter-class>
- filter>
- <filter-mapping>
- <filter-name>UrlRewriteFilterfilter-name>
- <url-pattern>/*url-pattern>
- <dispatcher>REQUESTdispatcher>
- <dispatcher>FORWARDdispatcher>
- filter-mapping>
在工程的warWEB-INF目錄下建立一個Url重寫設定檔:urlrewrite.xml
- xml version="1.0" encoding="utf-8"?>
- "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
-
- <urlrewrite>
- <rule enabled="true" match-type="regex">
- <note>UrlRewritenote>
- <condition type="request-filename" operator="notfile" name="notfile" next="and"/>
- <condition type="request-filename" operator="notdir" name="notdir" next="and"/>
- <from>/(.*)from>
- <to last="true" type="forward">/index.phpto>
- rule>
- urlrewrite>
-
這條規則就等同於.htaccess中的:
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
注意:這條規則可能會導致GAE本地管理http://localhost:8888/_ah/admin/失效,由於時間關係就不再修正.
4.測試:
在工程的war目錄下建立一個index.php檔案:
- php
- echo '<pre>';
- print_r($_SERVER);
- ?>
由於我已經將index.php設定為welcome檔案,所以直接開啟http://localhost:8888/
效果:
498)this.width=498;' onmousewheel = 'javascript:return big(this)' src="http://www.bkjia.com/uploadfile/2013/0904/20130904095435444.png" alt="\" style="margin: 0px; padding: 0px; border: 0px; " />
附上一些參考資料:
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們還在猶豫什麼,趕緊上吧~
http://www.bkjia.com/PHPjc/445669.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445669.htmlTechArticle1.下載quercus: http://quercus.caucho.com/ 版本當然最新的最好,因為原則上來說新版本對php支援程度更高,但是在自己測試的時候發現最新的4.0.25存在...