AzureでLaravel動かしてみた
[PHP] laravel.osaka #1 初めてのLaravel
JAZUG/Keiji Kamebuchi
@kosmosebi
Copyright© 2016, JAZUG All Rights Reserved.
Self Introduction
{
"name" : "Keiji Kamebuchi",
"corporation" : "pnop Inc.",
"mail" : "kamebuchi@pnop.co.jp",
"web" : "http://buchizo.wordpress.com/",
"twitter" : "@kosmosebi",
"award" : ["Microsoft MVP for Azure",
"Microsoft Regional Director"],
"timezone" : "-08:00 (PST)"
}
Copyright© 2016, JAZUG All Rights Reserved.
buchizo
Senior Fellow
@kosmosebi
Activities
Copyright© 2016, JAZUG All Rights Reserved.
https://azure.moe/
https://radio.azure.moe/
実は私は…
PHP / Laravel 初心者です
優しくしてください (;´Д`)
会社の同僚はPHP詳しい
でもOSSは好き
Azure チョットデキル
Azure/MicrosoftはOSS好き
Copyright© 2016, JAZUG All Rights Reserved.
Microsoft Azure?
Microsoftが提供しているクラウド
IaaS/PaaS/SaaS/MBaaS/IDaaSなど提
供中(ざっくり)
PaaSもいくつかある
(Windows上で動作する) Azure App
Service はPHPのランタイムが
標準で入ってる
• PHP 5.4 / 5.5 / 5.6 が標準で選択可能
• PHP 7 も拡張機能で簡単に追加可能
(ツール -> 拡張機能 -> 追加)
Copyright© 2016, JAZUG All Rights Reserved.
Azure App Service?
.NET Framework や PHP, Python, node.js が動くアプリケーショ
ンサーバー(PaaS)
用途によって大枠を4種類から選びます
• Web Apps / Mobile Apps / API Apps / Logic Apps
容易にスケール可能
GitやGitHubを使ったCI
FTP使ったデプロイも可
FreeプランからPremiumまで用途に応じて
選べる課金体系と性能
Zend Z-Ray使えたりもします
Copyright© 2016, JAZUG All Rights Reserved.
DBは?
Azureが提供
SQL Database (Microsoft SQL Server互換のSaaS)
DocumentDB (NoSQL)
Azure Table Storage (KVS) / Azure Blob Storage (ファイル)
3rd Party
ClearDB (MySQLを提供するSaaS)
• Azure上から作ったり操作できます
その他
SQLite (App Service上のローカルディスクに置く)
自前MySQL (IaaS上で自分で構築)
Copyright© 2016, JAZUG All Rights Reserved.
おまけ: DocumentDB
PHP用のプレーンなラッパーは作ったのですが(同僚が)
https://github.com/pnopjp/AzureDocumentDB-PHP
laravel用のドライバーなど作って活用してもらえると嬉しい
Copyright© 2016, JAZUG All Rights Reserved.
作り方
新規 -> Web + モバイル -> Web Apps
ホスト名、料金プラン(と作成先のデータセンター)、管理用
のグループを入力して作成
Copyright© 2016, JAZUG All Rights Reserved.
設定
設定 -> アプリケーション設定 -> PHP バージョンを 5.6に
Copyright© 2016, JAZUG All Rights Reserved.
設定
laravelは /public/ を参照する必要があるのでWeb Appsのルー
トの設定を変える
設定 -> アプリケーション設定 -> 仮想アプリケーションと
ディレクトリ
site¥wwwroot¥public にする
Copyright© 2016, JAZUG All Rights Reserved.
設定
拡張機能から composer をインストール
ツール -> 拡張機能 -> 追加 -> composer
追加後はWeb Appsを再起動
Copyright© 2016, JAZUG All Rights Reserved.
デプロイ
FTPを使う方法
作ったファイルをそのままアップロード
Gitなどを使う方法
リポジトリにpush
デプロイ後、Azure上でデプロイスクリプトが実行されます
• ※ 特に何もしなくてもいい…はず(後述)
Copyright© 2016, JAZUG All Rights Reserved.
Bad Know-How
Azure上にpushしたけどデプロイに失敗する
A1: composerが入ってないもしくは入れたけどちゃんと再起動して
ない
A2: オプティマイズに時間がかかりすぎてタイムアウトする
• → Laravelのスクリプトを調整してみると良いかも
• https://laracasts.com/discuss/channels/servers/deploying-as-an-azure-web-app
• app/Console フォルダに CompileCommonClasses.php を追加
• composer.json 内の post-install-cmdを空に
Copyright© 2016, JAZUG All Rights Reserved.
"post-install-cmd": [
],
CompileCommonClasses.php
<?php
namespace App¥Console¥Commands;
use Illuminate¥Foundation¥Console¥OptimizeCommand;
use Illuminate¥Support¥Composer;
class CompileCommonClasses extends OptimizeCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'optimize:classes';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Optimize common classes for Laravel';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Composer $composer)
{
parent::__construct($composer);
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Compiling common classes');
$this->compileClasses();
}
}
Copyright© 2016, JAZUG All Rights Reserved.
Copyright© 2016, JAZUG All Rights Reserved.
まとめ
意外と素直に動くと思います
MySQLだけちょっと苦しいところがある
その他サービスとの連携含めて興味がわいたら是非触って
みてください
Copyright© 2016, JAZUG All Rights Reserved.

AzureでLaravel動かしてみた