Homesteadをインストールしたは良いが、その後アプリを開発しようにもLaravelのファイルが無い。色々とググってみたが良く分からない。
そこで、HomesteadにログインしてcomposerでLaravelのプロジェクトを作成してみる事に。
% composer create-project laravel/laravel --prefer-dist <project name>
...(省略)...
そして、ホスト環境と共有されているフォルダにごっそりファイルをコピーする。
% cd ~/<project name>/
% cp -R .[a-z]* * ../Code/Laravel/
これでHomestead環境にHTTPアクセスすると、ちゃんとindex.phpが表示された。
しかし、何となくこの手順はキモいのだけれど、本当はどうやるべきなのか。
<追記>
しかし、とりあえずこれでLaravelエキスパート養成読本[モダンな開発を実現するPHPフレームワーク!]のチュートリアルで遊べる事が分かった。Laravel凄い。
2015年7月26日日曜日
Homesteadにログインする
ホスト環境(私の場合Mac)とフォルダが共有されているのは分かっていたが、シェルでログインするにはどうしたら良いのだろうかと調べてみるとこれがまた簡単。Vagrantって本当に凄いな。
vagrant sshと打てば良いらしい。
% vagrant ssh
A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.
なるほど、vagrant global-statusで取得したIDを指定しないといけないのね。
% vagrant global-status
id name provider state directory
------------------------------------------------------------------------
884a4c3 default virtualbox running /Users/<username>/Homestead
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
なるほど、これか。早速指定してみる。
% vagrant ssh 884a4c3
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-24-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Tue Oct 21 14:52:42 2014 from 10.0.2.2
vagrant@homestead:~%
おお。これだけでログイン出来てしまった。凄い便利だな。
vagrant sshと打てば良いらしい。
% vagrant ssh
A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.
なるほど、vagrant global-statusで取得したIDを指定しないといけないのね。
% vagrant global-status
id name provider state directory
------------------------------------------------------------------------
884a4c3 default virtualbox running /Users/<username>/Homestead
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
なるほど、これか。早速指定してみる。
% vagrant ssh 884a4c3
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-24-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Tue Oct 21 14:52:42 2014 from 10.0.2.2
vagrant@homestead:~%
おお。これだけでログイン出来てしまった。凄い便利だな。
Homesteadをインストールする
まず、VirtualBoxをインストール。MacOS向けのインストーラをここからダウンロードして実行するだけ。簡単。
次にVagrantをインストール。公式WebサイトのダウンロードページからMacOS向けのインストーラをダウンロードして実行するだけ。これも簡単。
% which vagrant/usr/local/bin/vagrant
なるほど、無事インストールされた模様。そこで更にHomesteadのインストール手順に従うと、、、
% vagrant box add laravel/homestead==> box: Loading metadata for box 'laravel/homestead'
box: URL: https://atlas.hashicorp.com/laravel/homestead
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.
1) virtualbox
2) vmware_desktop
Enter your choice: 1
==> box: Adding box 'laravel/homestead' (v0.2.7) for provider: virtualbox
box: Downloading: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.2.7/providers/virtualbox.box
==> box: Successfully added box 'laravel/homestead' (v0.2.7) for 'virtualbox'!
このダウンロードに結構時間が掛かる。大体1時間半くらいかかった。更にHomesteadをgit cloneする。
% git clone https://github.com/laravel/homestead.git HomesteadCloning into 'Homestead'...
remote: Counting objects: 1047, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 1047 (delta 2), reused 0 (delta 0), pack-reused 1036
Receiving objects: 100% (1047/1047), 158.21 KiB | 90.00 KiB/s, done.
Resolving deltas: 100% (606/606), done.
Checking connectivity... done.
さらにHomestead.yamlを作る。
% cd Homestead/
% sh init.sh Homestead initialized!
更にHomestead.yamlを見ると、ProviderはVirtualBoxなので問題無し。
% cd ~/.homestead/
% grep provider Homestead.yaml
provider: virtualbox
更にSSH Keyを作る。
% ssh-keygen -t rsa -C "you@homestead
"Generating public/private rsa key pair.
Enter file in which to save the key (/Users/<username>/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/<username>/.ssh/id_rsa.
Your public key has been saved in /Users/<username>/.ssh/id_rsa.pub....(中略)...
SSH Keyのファイル名を変える。
% cd ~/.ssh/
% mv id_rsa Homestead
% mv id_rsa.pub Homestead.pub
Homestead.yamlに色々と設定(以下、変えた所だけ)。
% cd ~/.homestead/
% vi Homestead.yaml
(前略)
ip: "192.168.11.11"
authorize: ~/.ssh/Homestead.pub
keys: - ~/.ssh/Homestead
(後略)
さて、ここでHomesteadを立ち上げる
% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 80 => 8000 (adapter 1)
default: 443 => 44300 (adapter 1)
default: 3306 => 33060 (adapter 1)
default: 5432 => 54320 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.3.14
default: VirtualBox Version: 5.0
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/<username>/Homestead
default: /home/vagrant/Code => /Users/<username>/<app name>
==> default: Running provisioner: file...
==> default: Running provisioner: shell...
default: Running: inline script
==> default: ssh-rsa XXXXX you@homestead
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-3a6mwz.sh
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-1qvawnk.sh
==> default: nginx stop/waiting
==> default: nginx start/running, process 1823
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1838
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-16v1opw.sh
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-1kgrvd.sh
==> default: createdb: database creation failed: ERROR: database "homestead" already exists
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-8nfae9.sh
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: inline script
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1928
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Updating to version c6cc6dd6070871f4b198ed39f76dd8047c116b02.
==> default: Downloading: Connecting...
==> default:
==> default: Downloading: 100%
==> default:
==> default:
==> default: Use composer self-update --rollback to return to version c43a39f7334ae3df968cd36a6eff0436bea0da75
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-5gwe60.sh
というわけで無事起動した模様。後は、/private/etc/hostsにhomestead.appを名前解決するエントリだけ追加して終了。
% cd /private/etc
% sudo vi hosts
Password: *****
エントリはこんな感じ。IPは~/.homestead/Homestead.yamlで設定したのに合わせる。
192.168.11.11 homestead.app
% ping homestead.app
PING homestead.app (192.168.11.11): 56 data bytes
64 bytes from 192.168.11.11: icmp_seq=0 ttl=64 time=0.650 ms
64 bytes from 192.168.11.11: icmp_seq=1 ttl=64 time=0.496 ms
.....
これでどうやら立ち上がった模様。
次にVagrantをインストール。公式WebサイトのダウンロードページからMacOS向けのインストーラをダウンロードして実行するだけ。これも簡単。
% which vagrant/usr/local/bin/vagrant
なるほど、無事インストールされた模様。そこで更にHomesteadのインストール手順に従うと、、、
% vagrant box add laravel/homestead==> box: Loading metadata for box 'laravel/homestead'
box: URL: https://atlas.hashicorp.com/laravel/homestead
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.
1) virtualbox
2) vmware_desktop
Enter your choice: 1
==> box: Adding box 'laravel/homestead' (v0.2.7) for provider: virtualbox
box: Downloading: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.2.7/providers/virtualbox.box
==> box: Successfully added box 'laravel/homestead' (v0.2.7) for 'virtualbox'!
このダウンロードに結構時間が掛かる。大体1時間半くらいかかった。更にHomesteadをgit cloneする。
% git clone https://github.com/laravel/homestead.git HomesteadCloning into 'Homestead'...
remote: Counting objects: 1047, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 1047 (delta 2), reused 0 (delta 0), pack-reused 1036
Receiving objects: 100% (1047/1047), 158.21 KiB | 90.00 KiB/s, done.
Resolving deltas: 100% (606/606), done.
Checking connectivity... done.
さらにHomestead.yamlを作る。
% cd Homestead/
% sh init.sh Homestead initialized!
更にHomestead.yamlを見ると、ProviderはVirtualBoxなので問題無し。
% cd ~/.homestead/
% grep provider Homestead.yaml
provider: virtualbox
更にSSH Keyを作る。
% ssh-keygen -t rsa -C "you@homestead
"Generating public/private rsa key pair.
Enter file in which to save the key (/Users/<username>/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/<username>/.ssh/id_rsa.
Your public key has been saved in /Users/<username>/.ssh/id_rsa.pub....(中略)...
SSH Keyのファイル名を変える。
% cd ~/.ssh/
% mv id_rsa Homestead
% mv id_rsa.pub Homestead.pub
Homestead.yamlに色々と設定(以下、変えた所だけ)。
% cd ~/.homestead/
% vi Homestead.yaml
(前略)
ip: "192.168.11.11"
authorize: ~/.ssh/Homestead.pub
keys: - ~/.ssh/Homestead
(後略)
さて、ここでHomesteadを立ち上げる
% vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 80 => 8000 (adapter 1)
default: 443 => 44300 (adapter 1)
default: 3306 => 33060 (adapter 1)
default: 5432 => 54320 (adapter 1)
default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.3.14
default: VirtualBox Version: 5.0
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /Users/<username>/Homestead
default: /home/vagrant/Code => /Users/<username>/<app name>
==> default: Running provisioner: file...
==> default: Running provisioner: shell...
default: Running: inline script
==> default: ssh-rsa XXXXX you@homestead
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-3a6mwz.sh
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-1qvawnk.sh
==> default: nginx stop/waiting
==> default: nginx start/running, process 1823
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1838
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-16v1opw.sh
==> default: Warning: Using a password on the command line interface can be insecure.
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-1kgrvd.sh
==> default: createdb: database creation failed: ERROR: database "homestead" already exists
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-8nfae9.sh
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Running provisioner: shell...
default: Running: inline script
==> default: php5-fpm stop/waiting
==> default: php5-fpm start/running, process 1928
==> default: Running provisioner: shell...
default: Running: inline script
==> default: Updating to version c6cc6dd6070871f4b198ed39f76dd8047c116b02.
==> default: Downloading: Connecting...
==> default:
==> default: Downloading: 100%
==> default:
==> default:
==> default: Use composer self-update --rollback to return to version c43a39f7334ae3df968cd36a6eff0436bea0da75
==> default: Running provisioner: shell...
default: Running: /var/folders/x_/0yldqsjd5ln1wwkq877_yms40000gq/T/vagrant-shell20150726-25772-5gwe60.sh
というわけで無事起動した模様。後は、/private/etc/hostsにhomestead.appを名前解決するエントリだけ追加して終了。
% cd /private/etc
% sudo vi hosts
Password: *****
エントリはこんな感じ。IPは~/.homestead/Homestead.yamlで設定したのに合わせる。
192.168.11.11 homestead.app
% ping homestead.app
PING homestead.app (192.168.11.11): 56 data bytes
64 bytes from 192.168.11.11: icmp_seq=0 ttl=64 time=0.650 ms
64 bytes from 192.168.11.11: icmp_seq=1 ttl=64 time=0.496 ms
.....
これでどうやら立ち上がった模様。
2015年7月18日土曜日
What's Forge!?
ForgeとかDigitalOceanとか、色々と登場するが、一体何なのか理解を整理する事に。
Laravel ForgeでさくらのVPSに環境を用意する
こちらを読むと、
ちなみに、こちらのページにはLaravel Homesteadについても記載があったので調べてみた。 Homesteadは、要するにLaravelを動かすのに必要なソフトがそっくり一式入った仮想マシンのイメージで、Vagrantを使ってVirtualBoxかVMWareの仮想マシン上にLaravelの開発環境を構築出来る様だ。
仮想環境構築ツール「Vagrant」で開発環境を仮想マシン上に自動作成する
良く知らなかったが、こういう仮想マシンの環境構築を自動で行うツールというのが普及している様だ。ということは、同じような技術を使えばForgeみたいなのも出来るわけだね。なるほど。
ちょっと今すぐにVirtualBoxを手元のMacに入れるのは難しいが、Homesteadも試してみたい。
<追記>
Laravel ForgeでさくらのVPSに環境を用意する
こちらを読むと、
- Laravelが動く環境をわずかな作業で構築し管理できるサービス
- 環境構築以外にも、gitプロジェクトのデプロイやcronスケジュール管理などもできる
ちなみに、こちらのページにはLaravel Homesteadについても記載があったので調べてみた。 Homesteadは、要するにLaravelを動かすのに必要なソフトがそっくり一式入った仮想マシンのイメージで、Vagrantを使ってVirtualBoxかVMWareの仮想マシン上にLaravelの開発環境を構築出来る様だ。
良く知らなかったが、こういう仮想マシンの環境構築を自動で行うツールというのが普及している様だ。ということは、同じような技術を使えばForgeみたいなのも出来るわけだね。なるほど。
ちょっと今すぐにVirtualBoxを手元のMacに入れるのは難しいが、Homesteadも試してみたい。
<追記>
登録:
投稿 (Atom)