Contenu connexe
Similaire à Dive into the Cloud with our buddy, lovely PHP! (20)
Dive into the Cloud with our buddy, lovely PHP!
- 1. Dive into the Cloud with our buddy,
lovely PHP!
関西PHP勉強会 #9 in JAWS FESTA Kansai 2013
September 26th, 2013
Sotaro OMURA
@omoon
- 46. #jawsfesta
PaaS
• 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/)
- 47. #jawsfesta
PaaS
• 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)
- 115. #jawsfesta
git clone
%
git
clone
git@github.com:PHP-‐Engineers-‐Training-‐Book/php_mook_sample.git
Cloning
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.
- 117. #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
- 118. #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
}
- 119. #jawsfesta
composer install (1)
$
curl
-‐s
http://getcomposer.org/installer
|
php
#!/usr/bin/env
php
All
settings
correct
for
using
Composer
Downloading...
Composer
successfully
installed
to:
/Users/omoon/Documents/php_mook_sample/
composer.phar
Use
it:
php
composer.phar
- 120. #jawsfesta
composer install (2)
%
php
composer.phar
install
Loading
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
- 121. #jawsfesta
1
<?php
2
require
__DIR__
.
'/../vendor/autoload.php';
3
4
$app
=
new
SilexApplication();
5
6
$app-‐>register(new
SilexProviderTwigServiceProvider(),
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
SilexProviderDoctrineServiceProvider(),
array(
14
'db.options'
=>
$config['db'],
15
));
16
17
//
トップ画面
18
$app-‐>get('/',
function(SilexApplication
$app)
{
19
$posts
=
$app['db']-‐>fetchAll('
20
SELECT
name,
message,
unix_timestamp(created)
as
created
21
FROM
posts
ORDER
BY
created
DESC
LIMIT
5
22
');
23
return
$app['twig']-‐>render('index.twig',
array(
24
'posts'
=>
$posts,
25
));
26
});
27
28
//
投稿処理
29
$app-‐>post('/speak',
function(SilexApplication
$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();
- 122. #jawsfesta
1
<?php
2
require
__DIR__
.
'/../vendor/autoload.php';
3
4
$app
=
new
SilexApplication();
5
6
$app-‐>register(new
SilexProviderTwigServiceProvider(),
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
SilexProviderDoctrineServiceProvider(),
array(
14
'db.options'
=>
$config['db'],
15
));
16
17
//
トップ画面
18
$app-‐>get('/',
function(SilexApplication
$app)
{
19
$posts
=
$app['db']-‐>fetchAll('
20
SELECT
name,
message,
unix_timestamp(created)
as
created
21
FROM
posts
ORDER
BY
created
DESC
LIMIT
5
22
');
23
return
$app['twig']-‐>render('index.twig',
array(
24
'posts'
=>
$posts,
25
));
26
});
27
28
//
投稿処理
29
$app-‐>post('/speak',
function(SilexApplication
$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();
- 123. #jawsfesta
1
<?php
2
require
__DIR__
.
'/../vendor/autoload.php';
3
4
$app
=
new
SilexApplication();
5
6
$app-‐>register(new
SilexProviderTwigServiceProvider(),
array(
7
'twig.path'
=>
__DIR__.'/../views',
8
));
- 124. #jawsfesta
10
//
データベース接続情報の読込
11
$env
=
getenv('APP_ENV')
?:
'development';
12
$config
=
require
__DIR__
.
"/../config/$env.php";
13
$app-‐>register(new
SilexProviderDoctrineServiceProvider(),
array(
14
'db.options'
=>
$config['db'],
15
));
- 125. #jawsfesta
17
//
トップ画面
18
$app-‐>get('/',
function(SilexApplication
$app)
{
19
$posts
=
$app['db']-‐>fetchAll('
20
SELECT
name,
message,
unix_timestamp(created)
as
created
21
FROM
posts
ORDER
BY
created
DESC
LIMIT
5
22
');
23
return
$app['twig']-‐>render('index.twig',
array(
24
'posts'
=>
$posts,
25
));
26
});
- 126. #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
}
- 127. #jawsfesta
28
//
投稿処理
29
$app-‐>post('/speak',
function(SilexApplication
$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
});