dive into the cloud with our buddy, lovely php!
DESCRIPTION
PHP と一緒にクラウドの世界へ飛び込もう。 JAWS FESTA Kansai 2013 でのスライドです。TRANSCRIPT
Dive into the Cloud with our buddy, lovely PHP!
関西PHP勉強会 #9 in JAWS FESTA Kansai 2013September 26th, 2013
Sotaro OMURA@omoon
#jawsfestaAbout Me
#jawsfestaAbout Me
• Sotaro OMURA
#jawsfestaAbout Me
• Sotaro OMURA•株式会社タップ
#jawsfestaAbout Me
• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)
#jawsfestaAbout Me
• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles
#jawsfestaAbout Me
• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles• omoon.org
#jawsfestaAbout Me
• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles• omoon.org•@omoon
#jawsfestaAbout Me
• Sotaro OMURA•株式会社タップ• PHP歴は12年ほど(最近はFuelPHPとか)• love noodles• omoon.org•@omoon
#jawsfesta
京セラドームと聞いて
#jawsfesta
#jawsfesta
安心しました
#jawsfesta今日話すこと
#jawsfesta今日話すこと
•クラウドにまつわる言葉の整理
#jawsfesta今日話すこと
•クラウドにまつわる言葉の整理•代表的クラウド紹介
#jawsfesta今日話すこと
•クラウドにまつわる言葉の整理•代表的クラウド紹介•実際にクラウドでPHPアプリケーションを公開する場合の具体的手順
#jawsfesta
ところで
#jawsfestaAbout Me
#jawsfestaAbout Me
#jawsfesta
#jawsfesta
#jawsfestaAbout Me
#jawsfestaAbout Me
#jawsfesta
#jawsfesta
クラウドとは
#jawsfestaクラウド3つの分類
#jawsfestaクラウド3つの分類
• IaaS (Infrastructure as a Service)
#jawsfestaクラウド3つの分類
• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)
#jawsfestaクラウド3つの分類
• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)• SaaS (Software as a Service)
#jawsfesta
IaaS
#jawsfesta
IaaS(あいあーす)
#jawsfesta
IaaS(いあーす)
#jawsfestaIaaS
#jawsfestaIaaS
•Amazon Web Services(http://aws.amazon.com/jp/)
#jawsfestaIaaS
•Amazon Web Services(http://aws.amazon.com/jp/)•さくらのクラウド(http://cloud.sakura.ad.jp/)
#jawsfestaIaaS
•Amazon Web Services(http://aws.amazon.com/jp/)•さくらのクラウド(http://cloud.sakura.ad.jp/)•NIFTY Cloud(http://cloud.nifty.com/)
#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/)
#jawsfesta
PaaS
#jawsfesta
PaaS(ぱあす)
#jawsfestaPaaS
#jawsfestaPaaS
• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)
#jawsfestaPaaS
• AppFog(https://www.appfog.com)• AWS Elastic Beanstalk(http://aws.amazon.com/jp/elasticbeanstalk/)• cloudControl(https://www.cloudcontrol.com)
#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)
#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)
#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/)
#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)
#jawsfesta
SaaS(さあす)
#jawsfestaSaaS
#jawsfestaSaaS
•Gmail
#jawsfestaSaaS
•Gmail•GitHub / Bitbucket
#jawsfestaSaaS
•Gmail•GitHub / Bitbucket•サイボウズLive (https://live.cybozu.co.jp)
#jawsfestaSaaS
•Gmail•GitHub / Bitbucket•サイボウズLive (https://live.cybozu.co.jp)• SendGrid (http://sendgrid.com)
#jawsfestaSaaS
•Gmail•GitHub / Bitbucket•サイボウズLive (https://live.cybozu.co.jp)• SendGrid (http://sendgrid.com)•New Relic (http://newrelic.com)
#jawsfesta
本には書けなかったはなし
#jawsfestaSaaS
#jawsfestaSaaS
•API経由で利用
#jawsfestaSaaS
•API経由で利用• SDKが用意されている場合が結構ある
#jawsfesta
#jawsfesta
#jawsfesta
#jawsfesta
#jawsfesta
#jawsfestaクラウド3つの分類のはなしでした
#jawsfestaクラウド3つの分類のはなしでした
• IaaS (Infrastructure as a Service)
#jawsfestaクラウド3つの分類のはなしでした
• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)
#jawsfestaクラウド3つの分類のはなしでした
• IaaS (Infrastructure as a Service)• PaaS (Platform as a Service)• SaaS (Software as a Service)
#jawsfesta
ええの?わるいの?
#jawsfesta
時と場合による
#jawsfesta考えられるメリット(かなり大雑把)
#jawsfesta考えられるメリット(かなり大雑把)
•すぐできる
#jawsfesta考えられるメリット(かなり大雑把)
•すぐできる•なかったことにできる
#jawsfesta考えられるメリット(かなり大雑把)
•すぐできる•なかったことにできる•コスト
#jawsfesta考えられるデメリット(かなり大雑把)
#jawsfesta考えられるデメリット(かなり大雑把)
•最後のところで融通がきかない
#jawsfesta考えられるデメリット(かなり大雑把)
•最後のところで融通がきかない•英語!
#jawsfesta考えられるデメリット(かなり大雑把)
•最後のところで融通がきかない•英語!•コスト
#jawsfesta
時と場合による
#jawsfesta
まずはためしてみましょう
#jawsfesta
#jawsfesta
#jawsfestaAbout Me
#jawsfestaAbout Me
#jawsfesta
ためしてみるにあたって
#jawsfesta
知っておくべき周辺技術
#jawsfesta
ssh
#jawsfesta
% ssh [email protected] [email protected]'s password:
#jawsfesta
% ssh [email protected] [email protected]'s password:
#jawsfestassh
#jawsfestassh
•パスワードは使わずに
#jawsfestassh
•パスワードは使わずに•鍵のペアをつくり
#jawsfestassh
•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密
#jawsfestassh
•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密•ひとつは相手に渡す
#jawsfestassh
•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密•ひとつは相手に渡す•やりとりするときに照合して
#jawsfestassh
•パスワードは使わずに•鍵のペアをつくり•ひとつは秘密•ひとつは相手に渡す•やりとりするときに照合して•アクセスしていいよ~
#jawsfesta
#jawsfesta
#jawsfesta
#jawsfesta
#jawsfestaコードのデプロイの1案(AWS)
#jawsfestaコードのデプロイの1案(AWS)
•Git のリモートリポジトリを作る
#jawsfestaコードのデプロイの1案(AWS)
•Git のリモートリポジトリを作る•サーバとの通信はキーペアを使ったssh
#jawsfestaコードのデプロイの1案(AWS)
•Git のリモートリポジトリを作る•サーバとの通信はキーペアを使ったssh•サーバ側で git pull
#jawsfestaコードのデプロイの1案(AWS)
•Git のリモートリポジトリを作る•サーバとの通信はキーペアを使ったssh•サーバ側で git pull• composer install など
#jawsfestaコードのデプロイの1案(Pagoda Box)
#jawsfestaコードのデプロイの1案(Pagoda Box)
•Git のリモートリポジトリを作る
#jawsfestaコードのデプロイの1案(Pagoda Box)
•Git のリモートリポジトリを作る•手元に git clone
#jawsfestaコードのデプロイの1案(Pagoda Box)
•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add
#jawsfestaコードのデプロイの1案(Pagoda Box)
•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add•サーバとの通信はキーペアを使ったssh
#jawsfestaコードのデプロイの1案(Pagoda Box)
•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add•サーバとの通信はキーペアを使ったssh•サーバ側に git push
#jawsfestaコードのデプロイの1案(Pagoda Box)
•Git のリモートリポジトリを作る•手元に git clone• Pagoda Boxのリポジトリを git remote add•サーバとの通信はキーペアを使ったssh•サーバ側に git push• composer install など
#jawsfestaサンプルコード
#jawsfestaサンプルコード
• https://github.com/PHP-Engineers-Training-Book/php_mook_sample
#jawsfestaサンプルコード
• https://github.com/PHP-Engineers-Training-Book/php_mook_sample
•デモします
#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.
#jawsfesta
#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
#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 }
#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
#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
#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();
#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();
#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 ));
#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 ));
#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 });
#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 }
#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 });
#jawsfesta
38 $app-‐>run();
#jawsfesta
とにかくためしてみましょう
#jawsfesta
ありがとうございました