目標
FuelPHPをHerokuのPHP7.0で使用
手順
初期設定/アプリ作成
とりあえず、scaffoldingするところまで
$ oil create todo $ cd todo $ vi fuel/app/config/config.php // ‘always_load’ と、その中の'packages'、’orm’のコメントアウトを外す $ oil g scaffold todo title:string desc:text $ oil r migrate
heroku用composerの編集
一番ハマった所。
16/3/6現在、HerokuのデフォルトはPHP7.0
FuelPHPはstableの1.7がPHP7.xに対応していない為、FuelPHP1.8を使用する
もしくは、composer.son内のrequireをHerokuが対応しているPHPバージョンを設定し、updateする
$ vi composer.json
"fuel/docs": "dev-1.7/master", "fuel/core": "dev-1.7/master", "fuel/auth": "dev-1.7/master", "fuel/email": "dev-1.7/master", "fuel/oil": "dev-1.7/master", "fuel/orm": "dev-1.7/master", "fuel/parser": "dev-1.7/master", //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "config": { "vendor-dir": "fuel/vendor", }
これらを以下のように編集する
"fuel/docs": "dev-1.8/develop", "fuel/core": "dev-1.8/develop", "fuel/auth": "dev-1.8/develop", "fuel/email": "dev-1.8/develop", "fuel/oil": "dev-1.8/develop", "fuel/orm": "dev-1.8/develop", "fuel/parser": "dev-1.8/develop", //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "config": { "bin-dir": "vendor/bin", "vendor-dir": "fuel/vendor", }
$ composer update
gitとProcfile
Procfileというwebのrootを指定するファイルを追加する + gitの設定
$ rm -rf .git $ git init $ vi .gitignore // “/composer.lock” を削除 $ vi Procfile web: vendor/bin/heroku-php-apache2 public/ $ git add . $ git commit -m “initial commit”
herokuのアプリケーション作成
heroku createだけでは –app APP_NAME を他のコマンド使うときに必要だった。
一度 "–app APP_NAME" か "-a APP_NAME" を使う必要が有り
$ heroku create > https://whispering-earth-59689.herokuapp.com/ | https://git.heroku.com/whispering-earth-59689.git $ heroku git:remote -a whispering-earth-59689 $ git push heroku master
herokuの環境設定
無料のaddonを入れる際にもクレジットカード登録が必要
$ heroku addons:add cleardb:ignite // MySQL $ heroku config:set FUEL_ENV=staging $ heroku config:add TZ=Asia/Tokyo $ heroku config > CLEARDB_DATABASE_URL: mysql://b3b44e8f2bbc37:fb0277d4@us-cdbr-iron-east-03.cleardb.net/heroku_00c6073515cd502?reconnect=true > FUEL_ENV: staging > TZ: Asia/Tokyo
db接続先設定
$ vi fuel/app/config/staging/db.php
$dbConfigPattern = '/mysql:\/\/(?:([^:^@]+)(?::([^@]+))?@)?([^:^\/]+)(?::(\d+))?\/([^?]+)/'; if (preg_match($dbConfigPattern, $_SERVER["CLEARDB_DATABASE_URL"], $matches)) { list($dbConfig, $dbuser, $dbpass, $dbhost, $dbport, $dbname) = $matches; return array( 'default' => array( 'connection' => array( 'dsn' => 'mysql:host='.$dbhost.';dbname='.$dbname, 'username' => $dbuser, 'password' => $dbpass, ), ), ); }
参考 https://www.tenpu.me/blog/2014/10/14/heroku-for-fuelphp/
herokuへデプロイ
ラストステップ いつもどおりコミットしてpushしてopenすると見れるはず!
$ git commit -am “fixed” $ git push heroku master $ heroku run bash $ php oil r migrate $ heroku open