Vagrant で
PHP 開発環境を作る
2013/10/26 shin1x1
Innovation EGG
ハンズオン準備

USBメモリから
ファイルコピー
(c) 2013 Masashi Shinbara @shin1x1
Agenda
• Vagrant とは
• ハンズオン
• ポイント

(c) 2013 Masashi Shinbara @shin1x1
PHP開発環境
• PHPを直接インストール

(ソース, MacPorts, Homebrew etc)

• XAMMP / MAMP
• Vagrant

(c) 2013 Masashi Shinbara @shin1x1
Vagrant?

(c) 2013 Masashi Shinbara @shin1x1
Vagrant
• 仮想環境をコマンドで操作
• 構築手順をコードで定義
• OSS(MITライセンス)
• VirtualBox との組み合わせ
(c) 2013 Masashi Shinbara @shin1x1
Vagrantなら
• プロジェクト毎に独立した環境を構築
• 他人と全く同じ環境を共有
• ホストPCとは分離された環境を構築

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 動作イメージ

Vagrant

仮想環境(VirutalBox)
[ホスト] 開発用PC

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 動作イメージ

仮想マシン起動

Vagrant

仮想環境(VirutalBox)
[ホスト] 開発用PC

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 動作イメージ

[ゲスト] 仮想マシン

Vagrant

仮想環境(VirutalBox)
[ホスト] 開発用PC

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 動作イメージ

プロビジョン
[ゲスト] 仮想マシン

Vagrant

仮想環境(VirutalBox)
[ホスト] 開発用PC

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 動作イメージ
Apache
PHP
MySQL / PostgreSQL

[ゲスト] 仮想マシン

Vagrant

仮想環境(VirutalBox)
[ホスト] 開発用PC

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 動作イメージ

仮想マシン破棄
[ゲスト] 仮想マシン

Vagrant

仮想環境(VirutalBox)
[ホスト] 開発用PC

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 動作イメージ

Vagrant

仮想環境(VirutalBox)
[ホスト] 開発用PC

(c) 2013 Masashi Shinbara @shin1x1
Vagrantで作るPHP開発環境

http://www.slideshare.net/shin1x1/xampp-mamp-vagrant-php

(c) 2013 Masashi Shinbara @shin1x1
Vagrant 覚えておきたい用語
•Boxファイル

=> 仮想マシンイメージファイル

•Vagrantfile

=> 仮想マシン構築設定

•vagrantコマンド

=> 全ての操作はこのコマンドで

(c) 2013 Masashi Shinbara @shin1x1
ハンズオン

(c) 2013 Masashi Shinbara @shin1x1
流れ
1. USBメモリから必要なファイルコピー
2. インストール、仮想マシン起動

(手順は、Gist を参照)
3. 上手く動いたら tweet (#phpkansai)

(c) 2013 Masashi Shinbara @shin1x1
手順資料

https://gist.github.com/shin1x1/7114143

#phpkansai

(c) 2013 Masashi Shinbara @shin1x1
vagrant 主なコマンド
• 仮想サーバ起動
$ vagrant up

• 仮想サーバへ SSH ログイン
$ vagrant ssh

• 仮想サーバ停止
$ vagrant halt

• 仮想サーバ停止+破棄
$ vagrant destroy
(c) 2013 Masashi Shinbara @shin1x1
ポイント

(c) 2013 Masashi Shinbara @shin1x1
Vagrantfile

•構築する仮想マシンの内容を記述
•Ruby
•分かる人が書けば良い

(c) 2013 Masashi Shinbara @shin1x1
synced_folder
•ホストPCのディレクトリと

仮想サーバのディレクトリを同期

•開発はホストPCで、

実行は仮想サーバで

•PhpStormやEclipseで開発可能
(c) 2013 Masashi Shinbara @shin1x1
synced_folder
$ ls /path/to/doctoot!
index.php sample.php

ホストPC

$ ls /share/doctoot!
index.php sample.php

仮想マシン
(c) 2013 Masashi Shinbara @shin1x1
synced_folder
PHPコード変更
<?php!
$foo = Foo::foo();

ホストPC
自動で同期
<?php!
$foo = Foo::foo();

仮想マシン
(c) 2013 Masashi Shinbara @shin1x1
プロジェクトへの適用

• プロジェクトリポジトリへ追加
• プロジェクト毎に作る
• 作業が終わったら、仮想マシンは停止

(c) 2013 Masashi Shinbara @shin1x1
参考1

http://docs.vagrantup.com/v2/
(c) 2013 Masashi Shinbara @shin1x1
参考2

http://www.amazon.co.jp/dp/1449335837
(c) 2013 Masashi Shinbara @shin1x1
参考3

http://www.amazon.co.jp/dp/B00F418SQ8
(c) 2013 Masashi Shinbara @shin1x1
@shin1x1

(c) 2013 Masashi Shinbara @shin1x1
One more thing

(c) 2013 Masashi Shinbara @shin1x1
黒い画面はいや!

(c) 2013 Masashi Shinbara @shin1x1
VagrantX
Mac OS X 用
GUIアプリ
絶賛開発中
(近日公開予定)

(c) 2013 Masashi Shinbara @shin1x1

Vagrant で PHP 開発環境を作る ハンズオン