PHP on GAEを試してみた。
Google App EngineでPHPを動かす。
いろいろ調べて時間はかかったけど最終的にはすごくシンプルになった。
quercus自体がGAEに対応するために修正が入ったんだと思います。
作業内容
appengine-java-SDKをインストール
以下を参照
http://code.google.com/intl/ja/appengine/downloads.html
環境変数 PATH を設定してあるとします。
プロジェクトの作成
プロジェクト用のディレクトリを作ります。
helloにしておきます。
$ mkdir -p hello/WEB-INF/lib
- quercusとjettyを配置
以下のサイトからダウンロードしてきます。
http://quercus.caucho.com/
http://dist.codehaus.org/jetty/jetty-6.1.17/
libにはいってる.jarファイルをhello/WEB-INF/libに配置します。
mkdirしたディレクトリにダウンロードしているとすると、
$ unzip jetty*.zip
$ unzip quercus-*.war -d querocus
$ cp jetty-*/lib/*.jar hello/WEB-INF/lib/
$ cp querocus/lib/*.jar hello/WEB-INF/lib/
と、いった感じになります。
web.xmlとかappengineとかを作ります。
- hello/WEB-INF/web.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <description>...</description> <servlet> <servlet-name>Quercus Servlet</servlet-name> <servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class> <init-param> <param-name>script-encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>ini-file</param-name> <param-value>WEB-INF/php.ini</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Quercus Servlet</servlet-name> <url-pattern>*.php</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/index.php</welcome-file> </welcome-file-list> </web-app>
- hello/WEB-INF/appengine-web.xml
<?xml version="1.0" encoding="utf-8"?> <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <application>...</application> <version>1</version> <static-files> <exclude path="/**.php" /> </static-files> <resource-files> <include path="/**.php" /> </resource-files> </appengine-web-app>
- hello/WEB-INF/index.php
<?php echo("hello, world"); ?>
web.xmlやappengine詳細はこのあたりに。
http://code.google.com/intl/ja/appengine/docs/java/config/webxml.html
http://code.google.com/intl/ja/appengine/docs/java/config/appconfig.html
ディレクトリ構成は以下のようになっているはずです。
$ find hello
hello
hello/index.php
hello/WEB-INF
hello/WEB-INF/appengine-web.xml
hello/WEB-INF/index.php
hello/WEB-INF/lib
hello/WEB-INF/lib/inject-16.jar
hello/WEB-INF/lib/javamail-141.jar
hello/WEB-INF/lib/jetty-6.1.17.jar
hello/WEB-INF/lib/jetty-util-6.1.17.jar
hello/WEB-INF/lib/resin.jar
hello/WEB-INF/lib/servlet-api-2.5-20081211.jar
hello/WEB-INF/web.xml
テストサーバの起動
$ dev_appserver.sh hello
あとはブラウザで
http://localhost:8080/index.php
にアクセス
サーバ起動字に文字化けするなら
export _JAVA_OPTIONS=-Duser.language=en
あたりを実行しておきましょう。
サーバーは再起動せずにindex.phpを編集しても、編集内容が反映されるようです。
デプロイはappenigen-web.xmlに取得したID書いて、
$ appcfg.sh update hello
とするだけです。(メアドとパスワードを要求されます。)
PHPはほとんどわからないので、これ以上深入りしませんが、
データベースまわりなどは一筋縄ではいかないかもしれません。
quercusのサイト内を検索すれば少しですが情報があるようです。