dive into the cloud with our buddy, lovely php!

130
Dive into the Cloud with our buddy, lovely PHP! 関西PHP勉強会 #9 in JAWS FESTA Kansai 2013 September 26th, 2013 Sotaro OMURA @omoon

Upload: sotaro-omura

Post on 04-Jul-2015

9.480 views

Category:

Technology


0 download

DESCRIPTION

PHP と一緒にクラウドの世界へ飛び込もう。 JAWS FESTA Kansai 2013 でのスライドです。

TRANSCRIPT

Page 1: Dive into the Cloud with our buddy, lovely PHP!

Dive into the Cloud with our buddy, lovely PHP!

関西PHP勉強会 #9 in JAWS FESTA Kansai 2013September 26th, 2013

Sotaro OMURA@omoon

Page 2: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

Page 3: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

• Sotaro OMURA

Page 4: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

• Sotaro OMURA•株式会社タップ

Page 5: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)

Page 6: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles

Page 7: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles• omoon.org

Page 8: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles• omoon.org•@omoon

Page 9: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles• omoon.org•@omoon

Page 10: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

京セラドームと聞いて

Page 11: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 12: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

安心しました

Page 13: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta今日話すこと

Page 14: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta今日話すこと

•クラウドにまつわる言葉の整理

Page 15: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta今日話すこと

•クラウドにまつわる言葉の整理•代表的クラウド紹介

Page 16: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta今日話すこと

•クラウドにまつわる言葉の整理•代表的クラウド紹介•実際にクラウドでPHPアプリケーションを公開する場合の具体的手順

Page 17: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

ところで

Page 18: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

Page 19: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

Page 20: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 21: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 22: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

Page 23: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

Page 24: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 25: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

クラウドとは

Page 26: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類

Page 27: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類

• IaaS (Infrastructure as a Service)

Page 28: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類

• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)

Page 29: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類

• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)• SaaS (Software as a Service)

Page 30: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

IaaS

Page 31: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

IaaS(あいあーす)

Page 32: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

IaaS(いあーす)

Page 33: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaIaaS

Page 34: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaIaaS

•Amazon Web Services(http://aws.amazon.com/jp/)

Page 35: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaIaaS

•Amazon Web Services(http://aws.amazon.com/jp/)•さくらのクラウド(http://cloud.sakura.ad.jp/)

Page 36: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaIaaS

•Amazon Web Services(http://aws.amazon.com/jp/)•さくらのクラウド(http://cloud.sakura.ad.jp/)•NIFTY Cloud(http://cloud.nifty.com/)

Page 37: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaIaaS

•Amazon Web Services(http://aws.amazon.com/jp/)•さくらのクラウド(http://cloud.sakura.ad.jp/)•NIFTY Cloud(http://cloud.nifty.com/)•Windows Azure(http://www.windowsazure.com/ja-jp/)

Page 38: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

PaaS

Page 39: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

PaaS(ぱあす)

Page 40: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

Page 41: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

• AppFog(https://www.appfog.com)

Page 42: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)

Page 43: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)• cloudControl(https://www.cloudcontrol.com)

Page 44: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)• cloudControl(https://www.cloudcontrol.com)• DotCloud(https://www.dotcloud.com)

Page 45: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)• cloudControl(https://www.cloudcontrol.com)• DotCloud(https://www.dotcloud.com)• Engine Yard(http://www.engineyard.co.jp)

Page 46: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)• cloudControl(https://www.cloudcontrol.com)• DotCloud(https://www.dotcloud.com)• Engine Yard(http://www.engineyard.co.jp)• Google App Engine(https://developers.google.com/appengine/)

Page 47: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaPaaS

• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)• cloudControl(https://www.cloudcontrol.com)• DotCloud(https://www.dotcloud.com)• Engine Yard(http://www.engineyard.co.jp)• Google App Engine(https://developers.google.com/appengine/)• Pagoda Box(http://pagodabox.com)

Page 48: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

SaaS(さあす)

Page 49: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

Page 50: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

•Gmail

Page 51: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

•Gmail•GitHub / Bitbucket

Page 52: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

•Gmail•GitHub / Bitbucket•サイボウズLive (https://live.cybozu.co.jp)

Page 53: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

•Gmail•GitHub / Bitbucket•サイボウズLive (https://live.cybozu.co.jp)• SendGrid (http://sendgrid.com)

Page 54: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

•Gmail•GitHub / Bitbucket•サイボウズLive (https://live.cybozu.co.jp)• SendGrid (http://sendgrid.com)•New Relic (http://newrelic.com)

Page 55: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

本には書けなかったはなし

Page 56: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

Page 57: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

•API経由で利用

Page 58: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaSaaS

•API経由で利用• SDKが用意されている場合が結構ある

Page 59: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 60: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 61: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 62: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 63: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 64: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類のはなしでした

Page 65: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類のはなしでした

• IaaS (Infrastructure as a Service)

Page 66: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類のはなしでした

• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)

Page 67: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaクラウド3つの分類のはなしでした

• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)• SaaS (Software as a Service)

Page 68: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

ええの?わるいの?

Page 69: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

時と場合による

Page 70: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるメリット(かなり大雑把)

Page 71: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるメリット(かなり大雑把)

•すぐできる

Page 72: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるメリット(かなり大雑把)

•すぐできる•なかったことにできる

Page 73: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるメリット(かなり大雑把)

•すぐできる•なかったことにできる•コスト

Page 74: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるデメリット(かなり大雑把)

Page 75: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるデメリット(かなり大雑把)

•最後のところで融通がきかない

Page 76: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるデメリット(かなり大雑把)

•最後のところで融通がきかない•英語!

Page 77: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta考えられるデメリット(かなり大雑把)

•最後のところで融通がきかない•英語!•コスト

Page 78: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

時と場合による

Page 79: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

まずはためしてみましょう

Page 80: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 81: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 82: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

Page 83: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaAbout Me

Page 84: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

ためしてみるにあたって

Page 85: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

知っておくべき周辺技術

Page 86: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

ssh

Page 88: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

%  ssh  [email protected]      [email protected]'s  password:

Page 89: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestassh

Page 90: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestassh

•パスワードは使わずに

Page 91: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestassh

•パスワードは使わずに•鍵のペアをつくり

Page 92: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestassh

•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密

Page 93: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestassh

•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密•ひとつは相手に渡す

Page 94: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestassh

•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密•ひとつは相手に渡す•やりとりするときに照合して

Page 95: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestassh

•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密•ひとつは相手に渡す•やりとりするときに照合して•アクセスしていいよ~

Page 96: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 97: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 98: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 99: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 100: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(AWS)

Page 101: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(AWS)

•Git のリモートリポジトリを作る

Page 102: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(AWS)

•Git のリモートリポジトリを作る•サーバとの通信はキーペアを使ったssh

Page 103: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(AWS)

•Git のリモートリポジトリを作る•サーバとの通信はキーペアを使ったssh•サーバ側で git pull

Page 104: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(AWS)

•Git のリモートリポジトリを作る•サーバとの通信はキーペアを使ったssh•サーバ側で git pull• composer install など

Page 105: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(Pagoda Box)

Page 106: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(Pagoda Box)

•Git のリモートリポジトリを作る

Page 107: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(Pagoda Box)

•Git のリモートリポジトリを作る•手元に git clone

Page 108: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(Pagoda Box)

•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add

Page 109: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(Pagoda Box)

•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add•サーバとの通信はキーペアを使ったssh

Page 110: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(Pagoda Box)

•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add•サーバとの通信はキーペアを使ったssh•サーバ側に git push

Page 111: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaコードのデプロイの1案(Pagoda Box)

•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add•サーバとの通信はキーペアを使ったssh•サーバ側に git push• composer install など

Page 112: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestaサンプルコード

Page 115: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestagit clone

%  git  clone  [email protected]:PHP-­‐Engineers-­‐Training-­‐Book/php_mook_sample.gitCloning  into  'php_mook_sample'...remote:  Counting  objects:  37,  done.remote:  Compressing  objects:  100%  (33/33),  done.remote:  Total  37  (delta  0),  reused  37  (delta  0)Receiving  objects:  100%  (37/37),  1.02  MiB  |  491  KiB/s,  done.

Page 116: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

Page 117: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta▾  php_mook_sample/    ▾  bin/            phpmig*  -­‐>  /Users/omoon/Documents/php_mook_sample/vendor/davedevelopment/phpmig/bin/phpmig    ▾  config/            development.php            pagoda.php    ▸  logs/    ▾  migrations/            20130711105053_CreateInitialTables.php*    ▾  public/        ▸  assets/            index.php    ▾  vendor/        ▸  composer/        ▸  davedevelopment/        ▸  doctrine/        ▸  pimple/        ▸  psr/        ▸  silex/        ▸  symfony/        ▸  twig/            autoload.php    ▾  views/            index.twig        Boxfile        composer.json        composer.lock        composer.phar*        phpmig.php

Page 118: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

 1  {  2          "require":  {  3                  "silex/silex":  "1.*",  4                  "doctrine/dbal":  "2.2.*",  5                  "twig/twig":  "~1.8",  6                  "davedevelopment/phpmig":  "*"  7          },  8          "config":  {  9                  "bin-­‐dir":  "bin/"10          }11  }

Page 119: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestacomposer install (1)

$  curl  -­‐s  http://getcomposer.org/installer  |  php#!/usr/bin/env  phpAll  settings  correct  for  using  ComposerDownloading...

Composer  successfully  installed  to:  /Users/omoon/Documents/php_mook_sample/composer.pharUse  it:  php  composer.phar

Page 120: Dive into the Cloud with our buddy, lovely PHP!

#jawsfestacomposer install (2)%  php  composer.phar  installLoading  composer  repositories  with  package  information...(略)...symfony/event-­‐dispatcher  suggests  installing  symfony/dependency-­‐injection  ()symfony/http-­‐kernel  suggests  installing  symfony/browser-­‐kit  ()symfony/http-­‐kernel  suggests  installing  symfony/dependency-­‐injection  ()symfony/http-­‐kernel  suggests  installing  symfony/finder  ()silex/silex  suggests  installing  symfony/browser-­‐kit  (>=2.3,<2.4-­‐dev)silex/silex  suggests  installing  symfony/css-­‐selector  (>=2.3,<2.4-­‐dev)silex/silex  suggests  installing  symfony/dom-­‐crawler  (>=2.3,<2.4-­‐dev)silex/silex  suggests  installing  symfony/form  (>=2.3,<2.4-­‐dev)Generating  autoload  files

Page 121: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta  1  <?php  2  require  __DIR__  .  '/../vendor/autoload.php';  3    4  $app  =  new  Silex\Application();  5    6  $app-­‐>register(new  Silex\Provider\TwigServiceProvider(),  array(  7          'twig.path'  =>  __DIR__.'/../views',  8  ));  9  10  //  データベース接続情報の読込11  $env  =  getenv('APP_ENV')  ?:  'development';12  $config  =  require  __DIR__  .  "/../config/$env.php";13  $app-­‐>register(new  Silex\Provider\DoctrineServiceProvider(),  array(14          'db.options'  =>  $config['db'],15  ));16  17  //  トップ画面18  $app-­‐>get('/',  function(Silex\Application  $app)  {19          $posts  =  $app['db']-­‐>fetchAll('20                  SELECT  name,  message,  unix_timestamp(created)  as  created21                  FROM  posts  ORDER  BY  created  DESC  LIMIT  522          ');23          return  $app['twig']-­‐>render('index.twig',  array(24                  'posts'  =>  $posts,25          ));26  });27  28  //  投稿処理29  $app-­‐>post('/speak',  function(Silex\Application  $app)  {30          $name  =  $app['request']-­‐>get('name');31          $message  =  $app['request']-­‐>get('message');32          if  ($name  &&  $message)  {33                  $app['db']-­‐>insert('posts',  array('name'  =>  $name,  'message'  =>  $message));34          }35          return  $app-­‐>redirect('/');36  });37  38  $app-­‐>run();

Page 122: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta  1  <?php  2  require  __DIR__  .  '/../vendor/autoload.php';  3    4  $app  =  new  Silex\Application();  5    6  $app-­‐>register(new  Silex\Provider\TwigServiceProvider(),  array(  7          'twig.path'  =>  __DIR__.'/../views',  8  ));  9  10  //  データベース接続情報の読込11  $env  =  getenv('APP_ENV')  ?:  'development';12  $config  =  require  __DIR__  .  "/../config/$env.php";13  $app-­‐>register(new  Silex\Provider\DoctrineServiceProvider(),  array(14          'db.options'  =>  $config['db'],15  ));16  17  //  トップ画面18  $app-­‐>get('/',  function(Silex\Application  $app)  {19          $posts  =  $app['db']-­‐>fetchAll('20                  SELECT  name,  message,  unix_timestamp(created)  as  created21                  FROM  posts  ORDER  BY  created  DESC  LIMIT  522          ');23          return  $app['twig']-­‐>render('index.twig',  array(24                  'posts'  =>  $posts,25          ));26  });27  28  //  投稿処理29  $app-­‐>post('/speak',  function(Silex\Application  $app)  {30          $name  =  $app['request']-­‐>get('name');31          $message  =  $app['request']-­‐>get('message');32          if  ($name  &&  $message)  {33                  $app['db']-­‐>insert('posts',  array('name'  =>  $name,  'message'  =>  $message));34          }35          return  $app-­‐>redirect('/');36  });37  38  $app-­‐>run();

Page 123: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

 1  <?php  2  require  __DIR__  .  '/../vendor/autoload.php';  3    4  $app  =  new  Silex\Application();  5    6  $app-­‐>register(new  Silex\Provider\TwigServiceProvider(),  array(  7          'twig.path'  =>  __DIR__.'/../views',  8  ));

Page 124: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

10  //  データベース接続情報の読込11  $env  =  getenv('APP_ENV')  ?:  'development';12  $config  =  require  __DIR__  .  "/../config/$env.php";13  $app-­‐>register(new  Silex\Provider\DoctrineServiceProvider(),  array(14          'db.options'  =>  $config['db'],15  ));

Page 125: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

17  //  トップ画面18  $app-­‐>get('/',  function(Silex\Application  $app)  {19          $posts  =  $app['db']-­‐>fetchAll('20                  SELECT  name,  message,  unix_timestamp(created)  as  created21                  FROM  posts  ORDER  BY  created  DESC  LIMIT  522          ');23          return  $app['twig']-­‐>render('index.twig',  array(24                  'posts'  =>  $posts,25          ));26  });

Page 126: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

 1  {  2          "require":  {  3                  "silex/silex":  "1.*",  4                  "doctrine/dbal":  "2.2.*",  5                  "twig/twig":  "~1.8",  6                  "davedevelopment/phpmig":  "*"  7          },  8          "config":  {  9                  "bin-­‐dir":  "bin/"10          }11  }

Page 127: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

28  //  投稿処理29  $app-­‐>post('/speak',  function(Silex\Application  $app)  {30          $name  =  $app['request']-­‐>get('name');31          $message  =  $app['request']-­‐>get('message');32          if  ($name  &&  $message)  {33                  $app['db']-­‐>insert('posts',  array('name'  =>  $name,  'message'  =>  $message));34          }35          return  $app-­‐>redirect('/');36  });

Page 128: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

38  $app-­‐>run();

Page 129: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

とにかくためしてみましょう

Page 130: Dive into the Cloud with our buddy, lovely PHP!

#jawsfesta

ありがとうございました