33

Click here to load reader

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

Embed Size (px)

DESCRIPTION

2013/10/26 Innovation EGG

Citation preview

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

2013/10/26 shin1x1

Innovation EGG

Vagrant で PHP 開発環境を作る

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

ハンズオン準備

(c) 2013 Masashi Shinbara @shin1x1

USBメモリから ファイルコピー

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

Agenda

(c) 2013 Masashi Shinbara @shin1x1

• Vagrant とは • ハンズオン • ポイント

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

PHP開発環境

(c) 2013 Masashi Shinbara @shin1x1

• PHPを直接インストール (ソース, MacPorts, Homebrew etc)

• XAMMP / MAMP • Vagrant

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

Vagrant?

(c) 2013 Masashi Shinbara @shin1x1

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

Vagrant

(c) 2013 Masashi Shinbara @shin1x1

• 仮想環境をコマンドで操作 • 構築手順をコードで定義 • OSS(MITライセンス) • VirtualBox との組み合わせ

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

Vagrantなら

(c) 2013 Masashi Shinbara @shin1x1

• プロジェクト毎に独立した環境を構築 • 他人と全く同じ環境を共有 • ホストPCとは分離された環境を構築

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

Vagrant 動作イメージ

(c) 2013 Masashi Shinbara @shin1x1

[ホスト] 開発用PC

仮想環境(VirutalBox)Vagrant

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

(c) 2013 Masashi Shinbara @shin1x1

[ホスト] 開発用PC

仮想環境(VirutalBox)Vagrant

仮想マシン起動

Vagrant 動作イメージ

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

(c) 2013 Masashi Shinbara @shin1x1

[ホスト] 開発用PC

仮想環境(VirutalBox)Vagrant

[ゲスト] 仮想マシン

Vagrant 動作イメージ

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

(c) 2013 Masashi Shinbara @shin1x1

[ホスト] 開発用PC

仮想環境(VirutalBox)Vagrant

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

Vagrant 動作イメージ

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

(c) 2013 Masashi Shinbara @shin1x1

[ホスト] 開発用PC

仮想環境(VirutalBox)Vagrant

[ゲスト] 仮想マシン

Apache PHP

MySQL / PostgreSQL

Vagrant 動作イメージ

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

(c) 2013 Masashi Shinbara @shin1x1

[ホスト] 開発用PC

仮想環境(VirutalBox)Vagrant

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

Vagrant 動作イメージ

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

(c) 2013 Masashi Shinbara @shin1x1

[ホスト] 開発用PC

仮想環境(VirutalBox)Vagrant

Vagrant 動作イメージ

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

Vagrantで作るPHP開発環境

(c) 2013 Masashi Shinbara @shin1x1

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

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

Vagrant 覚えておきたい用語

(c) 2013 Masashi Shinbara @shin1x1

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

•Vagrantfile => 仮想マシン構築設定

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

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

(c) 2013 Masashi Shinbara @shin1x1

ハンズオン

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

(c) 2013 Masashi Shinbara @shin1x1

流れ

1. USBメモリから必要なファイルコピー

2. インストール、仮想マシン起動 (手順は、Gist を参照)

3. 上手く動いたら tweet (#phpkansai)

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

(c) 2013 Masashi Shinbara @shin1x1

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

手順資料

#phpkansai

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

vagrant 主なコマンド

(c) 2013 Masashi Shinbara @shin1x1

• 仮想サーバ起動$ vagrant up

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

• 仮想サーバ停止$ vagrant halt

• 仮想サーバ停止+破棄$ vagrant destroy

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

(c) 2013 Masashi Shinbara @shin1x1

ポイント

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

(c) 2013 Masashi Shinbara @shin1x1

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

Vagrantfile

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

(c) 2013 Masashi Shinbara @shin1x1

•ホストPCのディレクトリと 仮想サーバのディレクトリを同期

•開発はホストPCで、 実行は仮想サーバで

•PhpStormやEclipseで開発可能

synced_folder

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

(c) 2013 Masashi Shinbara @shin1x1

synced_folder

$ ls /path/to/doctoot! index.php sample.php

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

�� �������������

ホストPC

仮想マシン

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

(c) 2013 Masashi Shinbara @shin1x1

synced_folder

<?php!$foo = Foo::foo();

<?php!$foo = Foo::foo();

�� �������������

ホストPC

仮想マシン

PHPコード変更

自動で同期

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

(c) 2013 Masashi Shinbara @shin1x1

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

プロジェクトへの適用

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

参考1

(c) 2013 Masashi Shinbara @shin1x1

http://docs.vagrantup.com/v2/

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

参考2

(c) 2013 Masashi Shinbara @shin1x1

http://www.amazon.co.jp/dp/1449335837

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

参考3

(c) 2013 Masashi Shinbara @shin1x1

http://www.amazon.co.jp/dp/B00F418SQ8

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

@shin1x1

(c) 2013 Masashi Shinbara @shin1x1

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

(c) 2013 Masashi Shinbara @shin1x1

One more thing

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

(c) 2013 Masashi Shinbara @shin1x1

黒い画面はいや!

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

(c) 2013 Masashi Shinbara @shin1x1

絶賛開発中 (近日公開予定)

Mac OS X 用 GUIアプリ

VagrantX