masalibの日記

システム開発、運用と猫の写真ブログです

クローラーのサービスを作る その2:サーバー調査2

Googleのある程度無料で動かせるサーバー(Google App Engine)で
おきまりのページ(helloworld)を作ってみました

ある程度というのは無料とは下記の範疇です
英語なので注意
https://cloud.google.com/appengine/docs/quotas

例)
ストレージバケット格納データ:5ギガバイトなど・・・

GOOGLE APP ENGINE SDK のインストール

https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_PHP


f:id:masalib:20150818221044j:plain

ダウンロードして起動すると
python2.7が必要ですよというメッセージが表示される

いれていない人は
Download Python | Python.org
からダウンロードする
(マルチバイト文字の問題があるので2.7.7以上いれたほうがいいです)

f:id:masalib:20150818221108j:plain


お約束のページが表示されるのでしたがってインストール
する
f:id:masalib:20150818221616j:plain

f:id:masalib:20150818221627j:plain

f:id:masalib:20150818221631j:plain

Google Developers Consoleに入ってプロジェクトを作成する

https://console.developers.google.com/project

f:id:masalib:20150818222039j:plain

適当なプロジェクトを入力する(masalibtest)


f:id:masalib:20150818222647j:plain

プロジェクトの作成が終わるとプロジェクトダッシュボードが表示される

f:id:masalib:20150818222723j:plain


Hello Worrdアプリのデプロイをクリックする


言語の選択画面が表示される
f:id:masalib:20150818222914j:plain

今回はPHPなのでPHPをクリックする

サンプルPHPがあるのでそちらをダウンロードする

f:id:masalib:20150818223013j:plain

ダウンロードしたファイルは以下のとおりです

appengine-try-php-master.zipの内容

helloworld.php

<!--?php
  echo 'Hello, world!';

app.yaml

    • >||

application: helloworld
version: 1
runtime: php55
api_version: 1

handlers:

  • url: /.*

script: helloworld.php
|


C:\test\appengine-try-php-masterに展開しました


コマンドラインを立ち上げて下記のコマンドを実行する

cd C:\test\
appcfg.py -A masalibtest update appengine-try-php-master

10:38 PM Application: masalibtest (was: helloworld); version: 1
10:38 PM Host: appengine.google.com
10:38 PM
Starting update of app: masalibtest, version: 1
10:38 PM Getting current resource limits.
Your browser has been opened to visit:↓初期の認証ページがたちあがります

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=550516889912.apps.googleusercontent.com&access_type=offline
If your browser is on a different machine then exit and re-run this
application with the command-line parameter

  --noauth_local_webserver

f:id:masalib:20150818224144j:plain

承認を押す

デプロイが開始される

Authentication successful.
10:39 PM Scanning files on local disk.
10:39 PM Cloning 2 application files.
10:40 PM Compilation starting.
10:40 PM Compilation completed.
10:40 PM Starting deployment.
10:40 PM Checking if deployment succeeded.
10:40 PM Deployment successful.
10:40 PM Checking if updated app version is serving.
10:40 PM Completed update of app: masalibtest, version: 1


ブラウザで以下のURLにアクセスする
http://masalibtest.appspot.com/

お決まりのページが表示されました~
f:id:masalib:20150818224513j:plain

思ったより簡単でした

app.yamlファイルでプログラムとプログラムパスを管理するのは
若干めんどくさいけど
raiilsでルールなのでまー仕方がないのかなと思っています

今後

GAEだとsmartyのテンプレートエンジンが使えないらしいので
TWIGというエンジンが使えるそうなのでそちらを調査したいと思います