イントロダクションIntroduction
Laravelはローカルでの開発環境を含め、PHP開発全体の経験を愉快なものにしようと頑張っています。Vagrantは、仮想マシーンの管理と事前設定を行う、簡単でエレガントな手段を提供しています。Laravel strives to make the entire PHP development experience delightful, including your local development environment. Vagrant[http://vagrantup.com] provides a simple, elegant way to manage and provision Virtual Machines.
Laravel Homestead(入植農地、「ホームステード」)はパッケージを事前に済ませた、Laravel公式の"box"で、PHPやHHVM、Webサーバー、その他のサーバーソフトウェアをローカルマシンにインストールする必要なく、素晴らしい開発環境を準備できます。オペレーティングシステムに関して、ごちゃごちゃになる心配はもうありません!Vagrantのboxは、完全に使い捨てできます。何かの調子が悪くなれば壊して、数分のうちにそのboxを再生成できます!Laravel Homestead is an official, pre-packaged Vagrant "box" that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!
Homesteadは、Windows、Mac、Linuxシステムで実行でき、Nginx Webサーバー、PHP5.6、MySQL、Postgres、Redis、Memcachedやその他、素晴らしいLaravelアプリケーションを開発するために必要な、クールなツールを全部含んでいます。Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 5.6, MySQL, Postgres, Redis, Memcached, and all of the other goodies you need to develop amazing Laravel applications.
注意: Windowsを使用している場合は、ハードウェア仮想化(VT-x)を有効にする必要があります。通常、BIOSにより有効にできます。Note: If you are using Windows, you may need to enable hardware virtualization (VT-x). It can usually be enabled via your BIOS.
Homesteadは現在、Vagrant1.7上で構築・テストされています。Homestead is currently built and tested using Vagrant 1.7.
パッケージされているソフトウェアIncluded Software
- Ubuntu 14.04Ubuntu 14.04
- PHP 5.6PHP 5.6
- HHVMHHVM
- NginxNginx
- MySQLMySQL
- PostgresPostgres
- Node(BowerとGrunt、Gulpも含む)Node (With Bower, Grunt, and Gulp)
- RedisRedis
- MemcachedMemcached
- BeanstalkdBeanstalkd
- Laravel EnvoyLaravel Envoy[/docs/{{version}}/envoy]
- BlackfireプロファイラーBlackfire Profiler[#blackfire-profiler]
インストールと準備Installation & Setup
VirtualBox/VMwareとVagrantのインストールInstalling VirtualBox / VMware & Vagrant
Homestead環境を起動する前に、VirtualBoxとVagrantをインストールする必要があります。両ソフトウェア共に、簡単に使用できるビジュアルなインストーラーが、人気のあるオペレーティングシステム全部に用意されています。Before launching your Homestead environment, you must install VirtualBox[https://www.virtualbox.org/wiki/Downloads] and Vagrant[http://www.vagrantup.com/downloads.html]. Both of these software packages provide easy-to-use visual installers for all popular operating systems.
VMwareVMware
VirtualBoxに付け加え、VMwareもHomesteadはサポートしています。VMwareプロバイダーを使用するには、VMware Fusion/DesktopとVMware Vagrantプラグインを購入する必要があります。VMwareは最初からより早い共有フォルダーを提供しています。In addition to VirtualBox, Homestead also supports VMware. To use the VMware provider, you will need to purchase both VMware Fusion / Desktop and the VMware Vagrant plug-in[http://www.vagrantup.com/vmware]. VMware provides much faster shared folder performance out of the box.
Vagrant Boxの追加Adding The Vagrant Box
VirtualBox/VMwareとVagrantをインストールし終えたら、laravel/homestead
boxをVagrantへ追加するために、以下のコマンドを端末で実行する必要があります。boxをダウンロードし終えるまで接続速度にもよりますが、数分かかるでしょう。Once
VirtualBox
/
VMware
and
Vagrant
have
been
installed,
you
should
add
the
laravel/homestead
box
to
your
Vagrant
installation
using
the
following
command
in
your
terminal.
It
will
take
a
few
minutes
to
download
the
box,
depending
on
your
Internet
connection
speed:
vagrant box add laravel/homestead
このコマンドが失敗する場合、完全なURLを指定する必要のある古いバージョンのVagrantを使用しています。If this command fails, you may have an old version of Vagrant that requires the full URL:
vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead
HomesteadのインストールInstalling Homestead
シンプルにリポジトリーをクローンし、Homesteadをインストールできます。自分の「ホーム」ディレクトリーの中のHomestead
フォルダーへリポジトリーをクローンするのは、自分のLaravel(とPHP)の全プロジェクトをホストしておくための、Homestead
Boxを用意するのだと考えてください。You
may
install
Homestead
manually
by
simply
cloning
the
repository.
Consider
cloning
the
repository
into
a
Homestead
folder
within
your
"home"
directory,
as
the
Homestead
box
will
serve
as
the
host
to
all
of
your
Laravel
(and
PHP)
projects:
git clone https://github.com/laravel/homestead.git Homestead
HomesteadリポジトリをCloneできたら、Homestead.yaml
設定ファイルを作成するため、Homesteadディレクトリでbash
init.sh
コマンドを実行してください。Once
you
have
cloned
the
Homestead
repository,
run
the
bash
init.sh
command
from
the
Homestead
directory
to
create
the
Homestead.yaml
configuration
file:
bash init.sh
Homestead.yaml
ファイルは、皆さんの~/.homestead
ディレクトリーへ設置されます。The
Homestead.yaml
file
will
be
placed
in
your
~/.homestead
directory.
プロバイダーの設定Configure Your Provider
Homestead.yaml
ファイルのprovider
キーはvirtualbox
、vmware_fusion
(Mac
OS
X)、vmware_workstation
(Windows)のどれかです。使用するプロバイダーの値を指定してください。The
provider
key
in
your
Homestead.yaml
file
indicates
which
Vagrant
provider
should
be
used:
virtualbox
,
vmware_fusion
(Mac
OS
X)
or
vmware_workstation
(Windows).
You
may
set
this
to
whichever
provider
you
prefer.
provider: virtualbox
SSHキーの設定Set Your SSH Key
次に、Homestead.yaml
ファイルを編集します。このファイルで、publicのSSHキーへのパスを設定でき、またメインマシーンと、Homestead仮想マシーンとの間で共有するフォルダーも指定できます。Next,
you
should
edit
the
Homestead.yaml
file.
In
this
file,
you
can
configure
the
path
to
your
public
SSH
key,
as
well
as
the
folders
you
wish
to
be
shared
between
your
main
machine
and
the
Homestead
virtual
machine.
SSHキーを持っていない? 一般的にMacとLinuxでは、以下のコマンドを使用し、SSHキーペアを生成できます。Don't have an SSH key? On Mac and Linux, you can generally create an SSH key pair using the following command:
ssh-keygen -t rsa -C "you@homestead"
Windowsでは、Gitをインストールし、Gitコマンドを実行するためのGit
Bash
シェルを使用します。別の方法として、PuTTYとPuTTYgenを使うこともできます。On
Windows,
you
may
install
Git[http://git-scm.com/]
and
use
the
Git
Bash
shell
included
with
Git
to
issue
the
command
above.
Alternatively,
you
may
use
PuTTY[http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html]
and
PuTTYgen[http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html].
SSHキーを作成したら、Homestead.yaml
ファイルの、authorize
プロパティーへ、キーのパスを指定してください。Once
you
have
created
a
SSH
key,
specify
the
key's
path
in
the
authorize
property
of
your
Homestead.yaml
file.
共有フォルダーの設定Configure Your Shared Folders
Homestead.yaml
ファイルのfolders
プロパティーには、Homestead環境と共有したい全フォルダーがリストされています。これらのフォルダーの中のファイルが変更されると、ローカルマシーンとHomestead環境との間で同期されます。必要なだけ共有フォルダーを設定してください!The
folders
property
of
the
Homestead.yaml
file
lists
all
of
the
folders
you
wish
to
share
with
your
Homestead
environment.
As
files
within
these
folders
are
changed,
they
will
be
kept
in
sync
between
your
local
machine
and
the
Homestead
environment.
You
may
configure
as
many
shared
folders
as
necessary!
NFSを有効にするには、同期するフォルダーにフラッグを指定するだけです。To enable NFS[http://docs.vagrantup.com/v2/synced-folders/nfs.html], just add a simple flag to your synced folder:
folders:
- map: ~/Code
to: /home/vagrant/Code
type: "nfs"
Nginxサイトの設定Configure Your Nginx Sites
Nginxには詳しくない?
問題ありません。sites
プロパティーで、Homestead環境上のフォルダーと「ドメイン」を簡単にマップできます。サイト設定のサンプルは、Homestead.yaml
ファイルに含まれています。これも必要に応じて、Homestead環境へサイトを好きなだけ追加してください。便利に使えるように、Homesteadは皆さんが作業する全てのLaravelプロジェクトの仮想環境を提供します!Not
familiar
with
Nginx?
No
problem.
The
sites
property
allows
you
to
easily
map
a
"domain"
to a
folder
on
your
Homestead
environment.
A
sample
site
configuration
is
included
in
the
Homestead.yaml
file.
Again,
you
may
add
as
many
sites
to
your
Homestead
environment
as
necessary.
Homestead
can
serve
as a
convenient,
virtualized
environment
for
every
Laravel
project
you
are
working
on!
hhvm
オプションをtrue
に設定すれば、簡単にHomesteadサイトでHHVMが使えるようになります。You
can
make
any
Homestead
site
use
HHVM[http://hhvm.com]
by
setting
the
hhvm
option
to
true
:
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
hhvm: true
それぞれのサイトはHTTPならば8000番ポートから、HTTPSなら44300ポートからアクセスできます。Each site will be accessible by HTTP via port 8000 and HTTPS via port 44300.
BashエイリアスBash Aliases
BashエイリアスをHomestead
boxに追加するには、~/.homestead
ディレクトリーのルートに、aliases
ファイルを追加するだけです。To
add
Bash
aliases
to
your
Homestead
box,
simply
add
to
the
aliases
file
in
the
root
of
the
~/.homestead
directory.
Vagrant boxを起動するLaunch The Vagrant Box
Homestead.yaml
のリンクを編集終えたら、Homesteadディレクトリーでvagrant
up
コマンドを実行してください。Once
you
have
edited
the
Homestead.yaml
to
your
liking,
run
the
vagrant
up
command
from
your
Homestead
directory.
Vagrantは仮想マシーンを起動し、共有フォルダーとNginxサイトを自動的に設定します!仮想マシーンを破壊するには、vagrant
destroy
--force
コマンドを使用します。Vagrant
will
boot
the
virtual
machine,
and
configure
your
shared
folders
and
Nginx
sites
automatically!
To
destroy
the
machine,
you
may
use
the
vagrant
destroy
--force
command.
Nginxサイトの「ドメイン」をメインマシーンのhosts
ファイルに追加するのを忘れないでください!
hosts
ファイルは、ローカルドメインへのリクエストをHomestead環境へリダイレクトしてくれます。MacとLinuxでは、このファイルは/etc/hosts
にあります。Windowsでは、C:\Windows\System32\drivers\etc\hosts
にあります。以下のような行をファイルへ追加してください。Don't
forget
to
add
the
"domains"
for
your
Nginx
sites
to
the
hosts
file
on
your
machine!
The
hosts
file
will
redirect
your
requests
for
the
local
domains
into
your
Homestead
environment.
On
Mac
and
Linux,
this
file
is
located
at
/etc/hosts
.
On
Windows,
it
is
located
at
C:\Windows\System32\drivers\etc\hosts
.
The
lines
you
add
to
this
file
will
look
like
the
following:
192.168.10.10 homestead.app
このIPアドレスを確実にHomestead.yaml
ファイルで指定してください。hosts
ファイルへドメインを追加したら、Webサーバーからサイトへアクセスできます!Make
sure
the
IP
address
listed
is
the
one
you
set
in
your
Homestead.yaml
file.
Once
you
have
added
the
domain
to
your
hosts
file,
you
can
access
the
site
via
your
web
browser!
http://homestead.app
データベースに接続する方法を学ぶには、続けて読んでください!To learn how to connect to your databases, read on!
使用方法Daily Usage
SSHによる接続Connecting Via SSH
Homesteadマシンへ頻繁に接続するでしょうから、Boxに簡単に接続できるように、ホストマシンで「エイリアス」を作成することを考えましょう。Since you will probably need to SSH into your Homestead machine frequently, consider creating an "alias" on your host machine to quickly SSH into the Homestead box:
alias vm="ssh vagrant@127.0.0.1 -p 2222"
このエイリアスを設定すると、システムのどこにいようと、"vm"コマンドを使ってHomesteadマシンへSSH接続できます。Once you create this alias, you can simply use the "vm" command to SSH into your Homestead machine from anywhere on your system.
そうでなければ、Homesteadディレクトリで
vagrant
ssh
コマンドを使用しましょう。Alternatively,
you
can
use
the
vagrant
ssh
command
from
your
Homestead
directory.
データベースへの接続Connecting To Your Databases
homestead
のデータベースは、最初からMySQLとPostgresのために設定されています。より便利にするために、Laravelのlocal
データベース設定がデフォルトで使用できるように設定されています。A
homestead
database
is
configured
for
both
MySQL
and
Postgres
out
of
the
box.
For
even
more
convenience,
Laravel's
local
database
configuration
is
set
to
use
this
database
by
default.
MySQLかPostgresデータベースに接続するには、メインマシーンからNavicatかSequel
Proを使い、127.0.0.1
の33060(MySQL)番ポートか、54320(Postgres)番ポートへ接続してください。ユーザー名とパスワードは、両方共にhomestead
/secret
です。To
connect
to
your
MySQL
or
Postgres
database
from
your
main
machine
via
Navicat
or
Sequel
Pro,
you
should
connect
to
127.0.0.1
and
port
33060
(MySQL)
or
54320
(Postgres).
The
username
and
password
for
both
databases
is
homestead
/
secret
.
注意: ホストマシーンから、データベースへ接続するには、標準的ではないポートだけを使用してください。Laravelのデータベース設定ファイル中では、デフォルトの3306と5432ポートを使用することができます。Laravelは仮想マシーンの内部で動作しているからです。Note: You should only use these non-standard ports when connecting to the databases from your main machine. You will use the default 3306 and 5432 ports in your Laravel database configuration file since Laravel is running within the Virtual Machine.
サイトを追加するAdding Additional Sites
Homestead環境が準備され実働した後に、LaravelアプリケーションをNginxサイトへ追加したいこともあるでしょう。希望するだけの数のNginxサイトをLaravelアプリケーションに追加し、一つのHomestead環境上で実行することができます。これには2つの方法があります。最初の方法は、シンプルにHomestead.yaml
ファイルへサイトを追加し、それからvagrant
provision
をHomesteadディレクトリーで実行してください。Once
your
Homestead
environment
is
provisioned
and
running,
you
may
want
to
add
additional
Nginx
sites
for
your
Laravel
applications.
You
can
run
as
many
Laravel
installations
as
you
wish
on a
single
Homestead
environment.
There
are
two
ways
to
do
this:
First,
you
may
simply
add
the
sites
to
your
Homestead.yaml
file
and
then
run
vagrant
provision
from
your
Homestead
directory.
注意: この方法は破壊的です。
provision
コマンドを実行すると、存在しているデータベースは破棄され、作成し直されます。Note: This process is destructive. When running theprovision
command, your existing databases will be destroyed and recreated.
もう一つの方法は、Homestead環境で使用できる、serve
スクリプトを使用します。serve
スクリプトを使用するには、Homestead環境へSSHで接続し、以下のコマンドを実行してください。Alternatively,
you
may
use
the
serve
script
that
is
available
on
your
Homestead
environment.
To
use
the
serve
script,
SSH
into
your
Homestead
environment
and
run
the
following
command:
serve domain.app /home/vagrant/Code/path/to/public/directory 80
注目:
serve
コマンドを実行した後は、新しいサイトをメインマシーンのhosts
ファイルへ追加するのを忘れずに!Note: After running theserve
command, do not forget to add the new site to thehosts
file on your main machine!
ポートPorts
以下のポートが、Homestead環境へポートフォワードされています。The following ports are forwarded to your Homestead environment:
- SSH: 2222 → フォワード先 22SSH: 2222 → Forwards To 22
- HTTP: 8000 → フォワード先 80HTTP: 8000 → Forwards To 80
- HTTPS: 44300 → Forwards To 443HTTPS: 44300 → Forwards To 443
- MySQL: 33060 → フォワード先 3306MySQL: 33060 → Forwards To 3306
- Postgres: 54320 → フォワード先 5432Postgres: 54320 → Forwards To 5432
追加のポートAdding Additional Ports
ご希望でしたら追加のポートをVagrant Boxへフォワードすることもできます。プロトコルを指定することもできます。If you wish, you may forward additional ports to the Vagrant box, as well as specify their protocol:
ports:
- send: 93000
to: 9300
- send: 7777
to: 777
protocol: udp
BlackfireプロファイラーBlackfire Profiler
SensioLabsのBlackfireプロファイラーはRAM、CPU時間、ディスクI/Oなどのコード実行情報を自動的に集めてくれます。Homesteadでは、皆さんのアプリケーションでとても簡単に使用できます。Blackfire Profiler[https://blackfire.io] by SensioLabs automatically gathers data about your code's execution, such as RAM, CPU time, and disk I/O. Homestead makes it a breeze to use this profiler for your own applications.
必要なパッケージは確実にHomestead
Boxへインストールされていますので、Homestead.yaml
ファイルにBlackfireのサーバーIDとトークンをセットするだけです。All
of
the
proper
packages
have
already
been
installed
on
your
Homestead
box,
you
simply
need
to
set
a
Blackfire
Server
ID
and
token
in
your
Homestead.yaml
file:
blackfire:
- id: your-server-id
token: your-server-token
client-id: your-client-id
client-token: your-client-token
Blackfireの認証情報を設定し終えたら、vagrant
provision
をHomesteadディレクトリーで実行し、Boxの設定準備を再実行してください。もちろん、WebブラウザにBlackfireを使いやすくする拡張をインストールするために、Blackfireのドキュメントをしっかり読んでおきましょう。Once
you
have
configured
your
Blackfire
credentials,
re-provision
the
box
using
vagrant
provision
from
your
Homestead
directory.
Of
course,
be
sure
to
review
the
Blackfire
documentation[https://blackfire.io/getting-started]
to
learn
how
to
install
the
Blackfire
companion
extension
for
your
web
browser.