イントロダクション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(入植農地、「ホームステード」)は、事前にパッケージされた公式の"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.6上で構築・テストされています。Homestead is currently built and tested using Vagrant 1.6.
パッケージされているソフトウェア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/ssh#envoy-task-runner]
- Fabric HipChat拡張Fabric HipChat Extension
インストールと準備Installation & Setup
VirtualBoxとVagrantのインストールInstalling VirtualBox & 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.
Vagrant Boxの追加Adding The Vagrant Box
VirtualBoxとVagrantをインストールし終えたら、laravel/homestead
boxをVagrantへ追加するために、以下のコマンドを端末で実行する必要があります。boxをダウンロードし終えるまで、接続速度にもよりますが、数分かかるでしょう。Once
VirtualBox
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
HomesteadのインストールInstalling Homestead
Gitから入手(ローカルにPHP無し)Manually Via Git (No Local PHP)
ローカルマシーンにPHPをインストールしたくなければ、シンプルにリポジトリーをクローンし、Homesteadを自分でインストールする方法が取れます。自分の「ホーム」ディレクトリーの中のHomestead
フォルダーへリポジトリーをクローンするのは、自分のLaravel(とPHP)の全プロジェクトをホストしておくための、Homestead
Boxを用意するのだと考えてください。Alternatively,
if
you
do
not
want
to
install
PHP
on
your
local
machine,
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コマンドラインツールがインストール済みであれば、bash
init.sh
コマンドでHomestead.yaml
設定ファイルを生成できます。Once
you
have
installed
the
Homestead
CLI
tool,
run
the
bash
init.sh
command
to
create
the
Homestead.yaml
configuration
file:
bash init.sh
Homestead.yaml
ファイルは、皆さんの~/.homestead
ディレクトリーへ設置されます。The
Homestead.yaml
file
will
be
placed
in
your
~/.homestead
directory.
ComposerとPHPツールの利用With Composer PHP Tool
Vagrantへboxを追加し終えたら、Composerのglobal
コマンドでHomestead
CLIツールをインストールする準備が整いました。Once
the
box
has
been
added
to
your
Vagrant
installation,
you
are
ready
to
install
the
Homestead
CLI
tool
using
the
Composer
global
command:
composer global require "laravel/homestead=~2.0"
端末からhomestead
コマンドを実行するときに、実行形式ファイルが見つかるように、~/.composer/vendor/bin
ディレクトリーへ実行パスを確実に通してください。Make
sure
to
place
the
~/.composer/vendor/bin
directory
in
your
PATH
so
the
homestead
executable
is
found
when
you
run
the
homestead
command
in
your
terminal.
Homestead
CLIツールをインストールし終えたら、init
コマンドを実行し、Homestead.yaml
設定ファイルを生成します。Once
you
have
installed
the
Homestead
CLI
tool,
run
the
init
command
to
create
the
Homestead.yaml
configuration
file:
homestead init
Homestead.yaml
ファイルは~/.homestead
ディレクトリーに設置されています。MacかLinuxシステムを使用している場合、homestead
edit
コマンドを端末で実行すれば、編集が行えます。The
Homestead.yaml
file
will
be
placed
in
the
~/.homestead
directory.
If
you're
using
a
Mac
or
Linux
system,
you
may
edit
Homestead.yaml
file
by
running
the
homestead
edit
command
in
your
terminal:
homestead edit
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!
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
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環境にSSHで接続するには、Homesteadディレクトリーでvagrant
ssh
コマンドを実行してください。To
connect
to
your
Homestead
environment
via
SSH,
issue
the
vagrant
ssh
command
from
your
Homestead
directory.
Homesteadマシンへ頻繁に接続するでしょうから、ホストマシンの「エイリアス」を作成することを考えてください。Since you will probably need to SSH into your Homestead machine frequently, consider creating an "alias" on your host machine:
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.
データベースへの接続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
を実行してください。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
.
別の方法は、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
注目:
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
- MySQL: 33060 → フォワード先 3306MySQL: 33060 → Forwards To 3306
- Postgres: 54320 → フォワード先 5432Postgres: 54320 → Forwards To 5432