HerokuでPHP
WEB+DB PRESSのvol.71のHeroku特集を見てRailsで試してみたけど
PHPも動くらしいのでやってみた。
Play framework2を試すはずなのに脱線しまくり。
ではHerokuでPHPを動かしてみる。
Herokuのアカウント持ってて、herokuコマンドインストール済みのログイン済みで以下。
$ mkdir myapp
$ cd myapp/
$ git init
Initialized empty Git repository in /path/myapp/.git/
$ vim index.php
<?php echo "Hello Heroku!!";
phpinfo();
?>
$ git add .
$ git commit -m "first commit"
[master (root-commit) 024c43b] first commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 index.php
$ heroku create --stack cedar
Creating evening-chamber-8448... done, stack is cedar
http://evening-chamber-8448.herokuapp.com/ | git@heroku.com:evening-chamber-8448.git
Git remote heroku added
$ git push heroku master
Counting objects: 3, done.
Writing objects: 100% (3/3), 252 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
-----> Heroku receiving push
-----> PHP app detected
-----> Bundling Apache version 2.2.22
-----> Bundling PHP version 5.3.10
-----> Discovering process types
Procfile declares types -> (none)
Default types for PHP -> web
-----> Compiled slug size: 9.5MB
-----> Launching... done, v4
http://evening-chamber-8448.herokuapp.com deployed to Heroku
To git@heroku.com:evening-chamber-8448.git
* [new branch] master -> master
今回であれば以下にブラウザでアクセスすれば表示されるはず(もう消したけど)
http://evening-chamber-8448.herokuapp.com/
すっごい簡単。。
※index.php置かないと
-----> Heroku receiving push ! Heroku push rejected, no Cedar-supported app detected To git@heroku.com:laxherokuphptest.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'git@heroku.com:laxherokuphptest.git'
とか言われるので注意。
で実際にphpinfoを見てみるとmbstringが無いのでググって調べる。
HerokuのBuildpackを利用してmbstringが有効なPHPサーバを立ててみた
buildpackを使ってみればいいのか。
ということでもう一度再挑戦。
$ mkdir myapp
$ cd myapp/
$ git init
Initialized empty Git repository in /path/myapp/.git/
$ vim index.php
<?php echo "Hello Heroku!!";
phpinfo();
?>
$ git add .
$ git commit -m "first commit"
[master (root-commit) 1dca1f5] first commit
1 files changed, 5 insertions(+), 0 deletions(-)
create mode 100644 index.php
$ heroku create --buildpack https://github.com/winglian/heroku-buildpack-php -s cedar
Creating stark-wildwood-1510... done, stack is cedar
BUILDPACK_URL=https://github.com/winglian/heroku-buildpack-php
http://stark-wildwood-1510.herokuapp.com/ | git@heroku.com:stark-wildwood-1510.git
Git remote heroku added
$ git push heroku master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
-----> Heroku receiving push
-----> Fetching custom git buildpack... done
-----> PHP app detected
-----> Extracting Apache 2.4.3 PHP 5.4.8 build 2.0-a4
-----> from http://vulcan-wlian.herokuapp.com/output/b8bace2a-2a8e-4441-acc3-eb8e6ad608a5
Creating Slug Identifier file with id: c24ac748141520640ed3220f65e2cde0
-----> Discovering process types
Procfile declares types -> (none)
Default types for PHP -> web
-----> Compiled slug size: 10.3MB
-----> Launching... done, v5
http://stark-wildwood-1510.herokuapp.com deployed to Heroku
To git@heroku.com:stark-wildwood-1510.git
* [new branch] master -> master
mbstring入ったーbuildpackすげー。
というかこのbuildpack PHP5.4.8だし
herokuでPHP面白いかも。
こんなのも見つけた。
Symfony2 on heroku (other php frameworks too)
