イントロダクションIntroduction
ローカル開発環境を含め、PHP開発全体を愉快なものにしようとLaravelは努力しています。Vagrantは、仮想マシーンの管理と事前設定を行う、簡単でエレガントな手段を提供しています。Laravel strives to make the entire PHP development experience delightful, including your local development environment. Vagrant[https://www.vagrantup.com] provides a simple, elegant way to manage and provision Virtual Machines.
Laravel Homestead(入植農地、「ホームステード」)はパッケージを事前に済ませた、Laravel公式の"box"で、PHPや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, 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サーバー、PHP7.1、MySQL、Postgres、Redis、Memcached、Nodeやその他、素晴らしいLaravelアプリケーションを開発するために必要な、クールなツールを全部含んでいます。Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 7.1, MySQL, Postgres, Redis, Memcached, Node, and all of the other goodies you need to develop amazing Laravel applications.
Note: {note} If you are using Windows, you may need to enable hardware virtualization (VT-x). It can usually be enabled via your BIOS. If you are using Hyper-V on a UEFI system you may additionally need to disable Hyper-V in order to access VT-x.
Windowsを使用している場合は、ハードウェア仮想化(VT-x)を有効にする必要があります。通常、BIOSにより有効にできます。UEFI system上のHyper-Vを使用している場合は、VT-xへアクセスするため、さらにHyper-Vを無効にする必要があります。
含まれるソフトウェアIncluded Software
- Ubuntu 16.04Ubuntu 16.04
- GitGit
- PHP 7.1PHP 7.1
- NginxNginx
- MySQLMySQL
- MariaDBMariaDB
- Sqlite3Sqlite3
- PostgresPostgres
- ComposerComposer
- Node (Yarn、PM2、Bower、Grunt、Gulpを含む)Node (With Yarn, PM2, Bower, Grunt, and Gulp)
- RedisRedis
- MemcachedMemcached
- BeanstalkdBeanstalkd
インストールと設定Installation & Setup
最初の段階First Steps
Homestead環境を起動する前に、VirtualBox 5.1とVMWare、もしくはParallels、それとVagrantをインストールする必要があります。全ソフトウェア共に簡単に使用できるビジュアルインストーラーが、人気のあるオペレーティングシステム全部に用意されています。Before launching your Homestead environment, you must install VirtualBox 5.1[https://www.virtualbox.org/wiki/Downloads], VMWare[https://www.vmware.com], or Parallels[http://www.parallels.com/products/desktop/] as well as Vagrant[https://www.vagrantup.com/downloads.html]. All of these software packages provide easy-to-use visual installers for all popular operating systems.
TVMwareプロバイダを使用するには、VMware Fusion/WorkstationとVMware Vagrantプラグインを購入する必要があります。無料ではありませんが、VMwareが提供する共有フォルダーは最初からよりスピーディーです。To use the VMware provider, you will need to purchase both VMware Fusion / Workstation and the VMware Vagrant plug-in[https://www.vagrantup.com/vmware]. Though it is not free, VMware can provide faster shared folder performance out of the box.
Parallelsプロバイダを使用するには、Parallels Vagrantプラグインをインストールする必要があります。これは無料です。To use the Parallels provider, you will need to install Parallels Vagrant plug-in[https://github.com/Parallels/vagrant-parallels]. It is free of charge.
Homestead Vagrant BoxのインストールInstalling The Homestead 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
このコマンドが失敗する場合、Vagrantを更新する必要があります。If this command fails, make sure your Vagrant installation is up to date.
HomesteadのインストールInstalling Homestead
リポジトリーをクローンするだけでHomesteadをインストールできます。自分の「ホーム」ディレクトリの中のHomestead
フォルダーへリポジトリーをクローンするのことは、自分のLaravel(とPHP)の全プロジェクトをホストしておくHomestead
Boxを用意するのだと考えてください。You
may
install
Homestead
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
projects:
cd ~
git clone https://github.com/laravel/homestead.git Homestead
Homesteadリポジトリをクローンできたら、Homestead.yaml
設定ファイルを生成するため、bash
init.sh
コマンドをHomesteadディレクトリで実行します。Homestead.yaml
ファイルは~/.homestead
隠しディレクトリの中に、生成されます。Once
you
have
cloned
the
Homestead
repository,
run
the
bash
init.sh
command
from
the
Homestead
directory
to
create
the
Homestead.yaml
configuration
file.
The
Homestead.yaml
file
will
be
placed
in
the
~/.homestead
hidden
directory:
// Mac / Linux...
bash init.sh
// Windows...
init.bat
Homestead設定Configuring Homestead
プロバイダの設定Setting Your Provider
~/.homestead/Homestead.yaml
ファイル中のprovider
キーは、Vagrantのプロバイダとして、virtualbox
、vmware_fusion
、vmware_workstation
、parallels
のどれを使用するかを指定します。使用するプロバイダの値を指定してください。The
provider
key
in
your
~/.homestead/Homestead.yaml
file
indicates
which
Vagrant
provider
should
be
used:
virtualbox
,
vmware_fusion
,
vmware_workstation
,
or
parallels
.
You
may
set
this
to
the
provider
you
prefer:
provider: virtualbox
共有ホルダーの設定Configuring 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:
folders:
- map: ~/Code
to: /home/vagrant/Code
NFSを有効にするには、同期するフォルダーにフラッグを指定するだけです。To enable NFS[https://www.vagrantup.com/docs/synced-folders/nfs.html], just add a simple flag to your synced folder configuration:
folders:
- map: ~/Code
to: /home/vagrant/Code
type: "nfs"
さらに、options
キー下にリストすれば、Vagrantの同期フォルダでサポートされているオプションを全て指定できます。You
may
also
pass
any
options
supported
by
Vagrant's
Synced
Folders[https://www.vagrantup.com/docs/synced-folders/basic_usage.html]
by
listing
them
under
the
options
key:
folders:
- map: ~/Code
to: /home/vagrant/Code
type: "rsync"
options:
rsync__args: ["--verbose", "--archive", "--delete", "-zz"]
rsync__exclude: ["node_modules"]
Nginxサイトの設定Configuring 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:
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
sites
プロパティをHomestead
boxのプロビジョニング後に変更した場合、仮想マシンのNginx設定を更新するため、vagrant
reload
--provision
を再実行する必要があります。If
you
change
the
sites
property
after
provisioning
the
Homestead
box,
you
should
re-run
vagrant
reload
--provision
to
update
the
Nginx
configuration
on
the
virtual
machine.
hostsファイルThe Hosts File
Nginxサイトの"domains"に追加したサイトをあなたのコンピューターのhosts
ファイルにも追加してください。hosts
ファイルはローカルドメインへのリクエストをHomestead環境へ転送してくれます。MacとLinuxでは、/etc/hosts
にこのファイルがあります。Windows環境では、C:\Windows\System32\drivers\etc\hosts
です。次の行のように追加してください。You
must
add
the
"domains"
for
your
Nginx
sites
to
the
hosts
file
on
your
machine.
The
hosts
file
will
redirect
requests
for
your
Homestead
sites
into
your
Homestead
machine.
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/Homestead.yaml
ファイルの中の値を確実に指定してください。ドメインをhosts
ファイルへ追加したら、Webブラウザーでサイトにアクセスできます。Make
sure
the
IP
address
listed
is
the
one
set
in
your
~/.homestead/Homestead.yaml
file.
Once
you
have
added
the
domain
to
your
hosts
file
and
launched
the
Vagrant
box
you
will
be
able
to
access
the
site
via
your
web
browser:
http://homestead.app
Vagrant Boxの実行Launching The Vagrant Box
Homestead.yaml
のリンクを編集終えたら、Homesteadディレクトリでvagrant
up
コマンドを実行してください。Vagrantは仮想マシーンを起動し、共有フォルダーとNginxサイトを自動的に設定します。Once
you
have
edited
the
Homestead.yaml
to
your
liking,
run
the
vagrant
up
command
from
your
Homestead
directory.
Vagrant
will
boot
the
virtual
machine
and
automatically
configure
your
shared
folders
and
Nginx
sites.
仮想マシーンを破壊するには、vagrant
destroy
--force
コマンドを使用します。To
destroy
the
machine,
you
may
use
the
vagrant
destroy
--force
command.
プロジェクトごとにインストールPer Project Installation
Homesteadをグローバルにインストールし、全プロジェクトで同じHomestead
Boxを共有する代わりに、Homesteadインスタンスを管理下のプロジェクトごとに設定することもできます。プロジェクトごとにHomesteadをインストールする利点は、Vagrantfile
をプロジェクトに用意すれば、プロジェクトに参加している他の人達も、vagrant
up
だけで仕事にとりかかれることです。Instead
of
installing
Homestead
globally
and
sharing
the
same
Homestead
box
across
all
of
your
projects,
you
may
instead
configure
a
Homestead
instance
for
each
project
you
manage.
Installing
Homestead
per
project
may
be
beneficial
if
you
wish
to
ship
a
Vagrantfile
with
your
project,
allowing
others
working
on
the
project
to
simply
vagrant
up
.
Homesteadをプロジェクトに直接インストールするには、Composerを使います。To install Homestead directly into your project, require it using Composer:
composer require laravel/homestead --dev
Homesteadがインストールできたら、Vagrantfile
とHomestead.yaml
ファイルをプロジェクトルートへ生成するためにmake
コマンドを使ってください。make
コマンドはHomestead.yaml
ファイルのsites
とfolders
ディレクティブを自動的に設定します。Once
Homestead
has
been
installed,
use
the
make
command
to
generate
the
Vagrantfile
and
Homestead.yaml
file
in
your
project
root.
The
make
command
will
automatically
configure
the
sites
and
folders
directives
in
the
Homestead.yaml
file.
Mac / Linux:Mac / Linux:
php vendor/bin/homestead make
Windows:Windows:
vendor\bin\homestead make
次にvagrant
up
コマンドを端末で実行し、ブラウザでhttp://homestead.app
のプロジェクトへアクセスしてください。/etc/hosts
ファイルにhomestead.app
か選んだドメインのエントリーを追加する必要はあることを覚えておきましょう。Next,
run
the
vagrant
up
command
in
your
terminal
and
access
your
project
at
http://homestead.app
in
your
browser.
Remember,
you
will
still
need
to
add
an
/etc/hosts
file
entry
for
homestead.app
or
the
domain
of
your
choice.
MariaDBのインストールInstalling MariaDB
MySQLの代わりにMariaDBを使用したい場合は、mariadb
オプションをHomestead.yaml
ファイルへ追加してください。このオプションはMySQLを削除し、MariaDBをインストールします。MariaDBはMySQLとそのまま置き換えられる代用ソフトウェアですので、mysql
データベースドライバをそのままアプリケーションで使用できます。If
you
prefer
to
use
MariaDB
instead
of
MySQL,
you
may
add
the
mariadb
option
to
your
Homestead.yaml
file.
This
option
will
remove
MySQL
and
install
MariaDB.
MariaDB
serves
as
a
drop-in
replacement
for
MySQL
so
you
should
still
use
the
mysql
database
driver
in
your
application's
database
configuration:
box: laravel/homestead
ip: "192.168.20.20"
memory: 2048
cpus: 4
provider: virtualbox
mariadb: true
使用方法Daily Usage
HomesteadへグローバルにアクセスするAccessing Homestead Globally
場合により、Homestead仮想マシンをファイルシステムのどこからでもvagrant
up
したい時もあるでしょう。Bashプロファイルへ簡単なBash関数を追加すれば実現できます。以下の関数はシステムのどこからでも、どんなVagrantコマンドでも実行できるようにし、自動的にHomesteadをインストールしてあるディレクトリで実行します。Sometimes
you
may
want
to
vagrant
up
your
Homestead
machine
from
anywhere
on
your
filesystem.
You
can
do
this
by
adding
a
simple
Bash
function
to
your
Bash
profile.
This
function
will
allow
you
to
run
any
Vagrant
command
from
anywhere
on
your
system
and
will
automatically
point
that
command
to
your
Homestead
installation:
function homestead() {
( cd ~/Homestead && vagrant $* )
}
エイリアス中の~/Homestead
パスを実際にHomesteadをインストール場所を示すように調整してください。関数がインストールできたら、システムのどこからでもhomestead
up
やhomestead
ssh
のように実行できます。Make
sure
to
tweak
the
~/Homestead
path
in
the
function
to
the
location
of
your
actual
Homestead
installation.
Once
the
function
is
installed,
you
may
run
commands
like
homestead
up
or
homestead
ssh
from
anywhere
on
your
system.
SSH接続Connecting Via SSH
Homesteadディレクトリでvagrant
ssh
端末コマンドを実行すれば、仮想マシンにSSHで接続できます。You
can
SSH
into
your
virtual
machine
by
issuing
the
vagrant
ssh
terminal
command
from
your
Homestead
directory.
しかし、Homesteadマシンには頻繁にSSHでアクセスする必要があると思いますから、ホストマシンから素早くHomestead boxへSSH接続できるように、上記の「関数」を追加することを検討してください。But, since you will probably need to SSH into your Homestead machine frequently, consider adding the "function" described above to your host machine to quickly SSH into the Homestead box.
データベースへの接続Connecting To Databases
homestead
のデータベースは、最初からMySQLとPostgresのために設定されています。より便利に使えるように、初めからフレームワークはこれらのデータベースを使用するように、Laravelの.env
ファイルで設定してあります。A
homestead
database
is
configured
for
both
MySQL
and
Postgres
out
of
the
box.
For
even
more
convenience,
Laravel's
.env
file
configures
the
framework
to
use
this
database
out
of
the
box.
MySQLかPostgresデータベースへ、ホストマシンからデータベースクライアントで接続するには、127.0.0.1
の33060
(MySQL)番ポートか、54320
(Postgres)番ポートへ接続してください。ユーザ名とパスワードは、両方共にhomestead
/secret
です。To
connect
to
your
MySQL
or
Postgres
database
from
your
host
machine's
database
client,
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
.
Note: {note} You should only use these non-standard ports when connecting to the databases from your host machine. You will use the default 3306 and 5432 ports in your Laravel database configuration file since Laravel is running within the virtual machine.
ホストマシーンからデータベースへ接続するには、標準的ではないポートだけを使用してください。Laravelのデータベース設定ファイル中では、デフォルトの3306と5432ポートを使用することができます。Laravelは仮想マシーンの内部で動作しているからです。
サイトの追加Adding Additional Sites
Homestead環境をプロビジョニングし、実働した後に、LaravelアプリケーションをNginxサイトへ追加したいこともあるでしょう。希望するだけのLaravelアプリケーションを一つのHomestead環境上で実行することができます。新しいサイトを追加するには、~/.homestead/Homestead.yaml
ファイルへ追加し、次にvagrant
reload
--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.
To
add
an
additional
site,
simply
add
the
site
to
your
~/.homestead/Homestead.yaml
file
and
then
run
the
vagrant
reload
--provision
terminal
command
from
your
Homestead
directory.
Cronスケジュール設定Configuring Cron Schedules
schedule:run
Artisanコマンドだけを毎分実行することにより、Cronジョブのスケジュールを簡単に行う方法をLaravelは提供しています。schedule:run
コマンドはApp\Console\Kernel
クラスの定義を調べ、どのジョブを実行すべきかを決定します。Laravel
provides
a
convenient
way
to
schedule
Cron
jobs[/docs/{{version}}/scheduling]
by
scheduling
a
single
schedule:run
Artisan
command
to
be
run
every
minute.
The
schedule:run
command
will
examine
the
job
schedule
defined
in
your
App\Console\Kernel
class
to
determine
which
jobs
should
be
run.
Homesteadサイトでschedule:run
コマンドを実行したい場合は、サイトを定義するときにschedule
オプションをtrue
に設定してください。If
you
would
like
the
schedule:run
command
to
be
run
for
a
Homestead
site,
you
may
set
the
schedule
option
to
true
when
defining
the
site:
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
schedule: true
こうしたサイト用のCronジョブは、仮想マシーンの/etc/cron.d
フォルダーの中に定義されます。The
Cron
job
for
the
site
will
be
defined
in
the
/etc/cron.d
folder
of
the
virtual
machine.
ポートPorts
以下のポートが、Homestead環境へポートフォワードされています。By default, 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 - フォワード先 443HTTPS: 44300 → Forwards To 443
- MySQL: 33060 - フォワード先 3306MySQL: 33060 → Forwards To 3306
- Postgres: 54320 - フォワード先 5432Postgres: 54320 → Forwards To 5432
追加のフォワードポートForwarding 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
ネットワークインターフェイスNetwork Interfaces
Homestead.yaml
ファイルのnetwork
プロパティは、Homestead環境のネットワークインターフェイスを設定します。多くのインターフェイスを必要に応じ設定可能です。The
networks
property
of
the
Homestead.yaml
configures
network
interfaces
for
your
Homestead
environment.
You
may
configure
as
many
interfaces
as
necessary:
networks:
- type: "private_network"
ip: "192.168.10.20"
ブリッジインターフェイスを有効にするには、bridge
項目を設定し、ネットワークタイプをpublic_network
へ変更します。To
enable
a
bridged[https://www.vagrantup.com/docs/networking/public_network.html]
interface,
configure
a
bridge
setting
and
change
the
network
type
to
public_network
:
networks:
- type: "public_network"
ip: "192.168.10.20"
bridge: "en1: Wi-Fi (AirPort)"
DHCPを有効にするには、設定からip
オプションを取り除いてください。To
enable
DHCP[https://www.vagrantup.com/docs/networking/public_network.html],
just
remove
the
ip
option
from
your
configuration:
networks:
- type: "public_network"
bridge: "en1: Wi-Fi (AirPort)"
Homesteadの更新Updating Homestead
2つの簡単な手順で、Homesteadをアップデートできます。最初にvagrant
box
update
コマンドを使い、Vagrant
boxを更新してください。You
can
update
Homestead
in
two
simple
steps.
First,
you
should
update
the
Vagrant
box
using
the
vagrant
box
update
command:
vagrant box update
次に、Homesteadのソースコードを更新する必要があります。リポジトリをクローンしている場合は、リポジトリをクローンしたもともとの場所で、git
pull
origin
master
を単に実行するするだけです。Next,
you
need
to
update
the
Homestead
source
code.
If
you
cloned
the
repository
you
can
simply
git
pull
origin
master
at
the
location
you
originally
cloned
the
repository.
composer.json
ファイルにより、Homesteadをインストールしている場合は、composer.json
ファイルに"laravel/homestead":
"^4"
が含まれていることを確認し、依存パッケージを更新してください。If
you
have
installed
Homestead
via
your
project's
composer.json
file,
you
should
ensure
your
composer.json
file
contains
"laravel/homestead":
"^4"
and
update
your
dependencies:
composer update
旧バージョンOld Versions
Homestead.yaml
ファイルに以下の行を付け加えることで、Homesteadが使用するboxのバージョンを簡単にオーバーライドできます。You
can
easily
override
the
version
of
the
box
that
Homestead
uses
by
adding
the
following
line
to
your
Homestead.yaml
file:
version: 0.6.0
一例:An example:
box: laravel/homestead
version: 0.6.0
ip: "192.168.20.20"
memory: 2048
cpus: 4
provider: virtualbox
古いバージョンのHomestead boxを使用する場合は、互換性のあるバージョンのHomesteadソースコードへ合わせる必要があります。下図はサポートされているboxのバージョンを表し、使用すべきHomesteadソースコードのバージョンとPHPバージョンです。When you use an older version of the Homestead box you need to match that with a compatible version of the Homestead source code. Below is a chart which shows the supported box versions, which version of Homestead source code to use, and the version of PHP provided:
HomesteadバージョンHomestead Version | BoxバージョンBox Version | |
---|---|---|
PHP 7.0PHP 7.0 | 3.1.03.1.0 | 0.6.00.6.0 |
PHP 7.1PHP 7.1 | 4.0.04.0.0 | 1.0.01.0.0 |