Readouble

Laravel 5.1 Laravel Homestead

イントロダクションIntroduction

ローカル開発環境を含め、PHP開発全体を愉快なものにしようとLaravelは努力しています。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サーバー、PHP7.0、MySQL、Postgres、Redis、Memcached、Nodeやその他、素晴らしいLaravelアプリケーションを開発するために必要な、クールなツールを全部含んでいます。Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 7.0, MySQL, Postgres, Redis, Memcached, Node, and all of the other goodies you need to develop amazing Laravel applications.

注意: Windowsを使用している場合は、ハードウェア仮想化(VT-x)を有効にする必要があります。通常、BIOSにより有効にできます。UEFI system上のHyper-Vを使用している場合は、VT-xへアクセスするため、さらにHyper-Vを無効にする必要があります。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.

含まれるソフトウェアIncluded Software

  • Ubuntu 14.04Ubuntu 14.04
  • GitGit
  • PHP 7.0PHP 7.0
  • HHVMHHVM
  • NginxNginx
  • MySQLMySQL
  • MariaDBMariaDB
  • Sqlite3Sqlite3
  • PostgresPostgres
  • ComposerComposer
  • Node (PM2とBower、Grunt、Gulpを含む)Node (With PM2, Bower, Grunt, and Gulp)
  • RedisRedis
  • MemcachedMemcached
  • BeanstalkdBeanstalkd

インストールと設定Installation & Setup

最初の段階First Steps

Homestead環境を起動する前に、VirtualBox 5.xVagrantをインストールする必要があります。両ソフトウェア共に簡単に使用できるビジュアルインストーラーが、人気のあるオペレーティングシステム全部に用意されています。Before launching your Homestead environment, you must install VirtualBox 5.x[https://www.virtualbox.org/wiki/Downloads] or VMWare[http://www.vmware.com] as well as Vagrant[http://www.vagrantup.com/downloads.html]. All of these software packages provide easy-to-use visual installers for all popular operating systems.

VMwareプロバイダーを使用するには、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[http://www.vagrantup.com/vmware]. Though it is not free, VMware can provide faster shared folder performance out of the box.

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:

bash init.sh

Homestead設定Configuring Homestead

プロバイダーの設定Setting Your Provider

~/.homestead/Homestead.yamlファイル中のproviderキーは、Vagrantのプロバイダとして、virtualboxvmware_fusionvmware_workstationのどれを使用するかを指定します。使用するプロバイダーの値を指定してください。The provider key in your ~/.homestead/Homestead.yaml file indicates which Vagrant provider should be used: virtualbox, vmware_fusion, or vmware_workstation. 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[http://docs.vagrantup.com/v2/synced-folders/nfs.html], just add a simple flag to your synced folder configuration:

folders:
    - map: ~/Code
      to: /home/vagrant/Code
      type: "nfs"

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

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

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, you can 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がインストールできたら、VagrantfileHomestead.yamlファイルをプロジェクトルートへ生成するためにmakeコマンドを使ってください。makeコマンドはHomestead.yamlファイルのsitesfoldersディレクティブを自動的に設定します。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 makevendor\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 alias to your Bash profile. This alias will allow you to run any Vagrant command from anywhere on your system and will automatically point that command to your Homestead installation:

alias homestead='function __homestead() { (cd ~/Homestead && vagrant $*); unset -f __homestead; }; __homestead'

エイリアス中の~/Homesteadパスを実際にHomesteadをインストール場所を示すように調整してください。エイリアスがインストールできたら、システムのどこからでもhomestead uphomestead sshのように実行できます。Make sure to tweak the ~/Homestead path in the alias to the location of your actual Homestead installation. Once the alias 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 "alias" 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データベースへ、NavicatかSequel Proを経由して接続するには、127.0.0.133060(MySQL)番ポートか、54320(Postgres)番ポートへ接続してください。ユーザー名とパスワードは、両方共にhomestead/secretです。To connect to your MySQL or Postgres database from your host 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 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.

サイトの追加Adding Additional Sites

Homestead環境をプロビジョニングし、実働した後に、LaravelアプリケーションをNginxサイトへ追加したいこともあるでしょう。希望するだけのLaravelアプリケーションを一つのHomestead環境上で実行することができます。新しいサイトを追加するには、~/.homestead/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. To add an additional site, simply add the site to your ~/.homestead/Homestead.yaml file and then run the vagrant 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 scheduled 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)"

章選択

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作