在GAE上搭建PHP環境並開啟URL重寫_PHP教程

來源:互聯網
上載者:User
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檔案的支援:

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

在web.xml中添加一個servlet:

 
  1. <servlet>
  2. <servlet-name>Quercus Servletservlet-name>
  3. <servlet-class>com.caucho.quercus.servlet.GoogleQuercusServletservlet-class>
  4. servlet>

添加對php檔案的映射:

 
  1. <servlet-mapping>
  2. <servlet-name>Quercus Servletservlet-name>
  3. <url-pattern>*.phpurl-pattern>
  4. servlet-mapping>

3.實現URL重寫(通過UrlRewriteFilter實現):

下載UrlRewriteFilter,將urlrewritefilter-*.jar拷貝在工程的warWEB-INFlib目錄下

在web.xml中添加URL過濾

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

在工程的warWEB-INF目錄下建立一個Url重寫設定檔:urlrewrite.xml

 
  1. xml version="1.0" encoding="utf-8"?>
  2. "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
  3. <urlrewrite>
  4. <rule enabled="true" match-type="regex">
  5. <note>UrlRewritenote>
  6. <condition type="request-filename" operator="notfile" name="notfile" next="and"/>
  7. <condition type="request-filename" operator="notdir" name="notdir" next="and"/>
  8. <from>/(.*)from>
  9. <to last="true" type="forward">/index.phpto>
  10. rule>
  11. urlrewrite>

這條規則就等同於.htaccess中的:

RewriteCond %{SCRIPT_FILENAME} !-f

RewriteCond %{SCRIPT_FILENAME} !-d

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

注意:這條規則可能會導致GAE本地管理http://localhost:8888/_ah/admin/失效,由於時間關係就不再修正.

4.測試:

在工程的war目錄下建立一個index.php檔案:

 
  1. php
  2. echo '<pre>';
  3. print_r($_SERVER);
  4. ?>

由於我已經將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存在...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.