Laravel(라라벨) Homestead 사용하기

Laravel(라라벨) Homestead 사용하기

Laravel(라라벨) Homestead 사용하기

Laravel은 로컬 개발환경을 포함해서 PHP 개발 경험 전체를 즐겁도록 하기 위한 노력을 많이 한다고 설명하며, 그것은 Homestead다.

(먼저 필요한 것 중에서) Vagrant는 쉽고 우아한 방법으로 가상머신 관리와 공급을 제공한다. ( 가상화 인스턴스인 Virtual Machine을 관리하는 소프트웨어 이다. )

Oracle Virtual Box 와 Vagrant 를 설치 해야 한다.

여러 Provider를 지원하기는 하지만, 기본 Provider는 VirtualBox이다.

=> Vagrant 설치후 확인 : vagrant -v

http://rangken.github.io/blog/2015/vagrant-1/ ( Vagrant 기본 설정 및 명령어 )

Laravel Homestead는 공식 지원이며, 미리 설치된 Vagrant box 이며, 로컬 머신에 PHP, HHVM, web server 또는 어떤 다른 소프트웨어의 설치가 필요없는 개발 환경을 제공한다.

=> 다양한 box들 : https://atlas.hashicorp.com/boxes/search

0. 설치 환경

- window 10

- virtual box 4.3.12 ( 5.0.x ~ 5.1.x 는 설치시 에러 )

1. 설치 및 셋업

1) HomeStead Vagrant Box 설치

-- Vagrant Box는 일종의 스냅샷 이미지 ( OS와 프로그램이 미리 설치되어 있는 이미지)

-- Ubuntu 16.04.01 (homestead 4.4.0) ,PHP 7.1, HHVM, Nginx

-- MySQL, Postgres, NodeJs, Redis, Memcached, Beanstalkd, Blackfire Profiler

> vargrant box add laravel/homestead

=> C:\Users\[계정명]\.vagrant.d\boxes\laravel-VAGRANTSLASH-homestead\0.4.0\virtualbox 에 가상 디스크가 생긴다.

2) Homestead 프로젝트 설치

--> git bash를 사용할 수 있는 환경을 구성후에 사용 할 것

(1) 홈 디렉토리에서 저장소 clone

> cd ~ > git clone https://github.com/laravel/homestead.git Homestead

(2) Homestead 디렉토리에서 git bash실행

> cd ~/Homestead > bash init.sh

=> 홈 디렉토리밑에 .homestead/Homestead.yaml설정파일 생성

또는 > laravel new example 와 같이 어플리케이션을 직접 생성

(3) Homestead.yaml 설정

- cpu 개수는 적당히 늘려주기

- 로컬 Window 공유 디렉토리 생성 하기 ( ~/Code )

- sites변경시에는 갱신 : >vagrant reload --provision

--- ip: "192.168.10.10" # homestead VM이 사용할 주소 memory: 2048 cpus: 2 provider: virtualbox # Virtual Machine Provider authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa # SSH로그인에 사용할 private key folders: - map: ~/Code # 로컬 디렉토리 경로 to: /home/vagrant/Code # VM의 디렉토리 경로 sites: - map: homestead.app # 도메인 이름 to: /home/vagrant/Code/Laravel/public # 웹서버의 Document Root databases: - homestead # blackfire: # - id: foo # token: bar # client-id: foo # client-token: bar # ports: # - send: 50000 # to: 5000 # - send: 7777 # to: 777 # protocol: udp

- project 생성 : ~Code > composer create-project laravel/laravel --no-dev --prefer-dist -vvv laravel

(4) Host 파일 설정하기

-- 웹페이지 접속을 위한 도메인 등록

# %WINDIR%\System32\drivers\etc\hosts 192.168.10.10 homestead.app

(5) Vagrant Box 실행

-- boot the VM & 자동으로 공유폴더와 Nginx 사이트를 구성한다.

C:\Users\[계정명]\Homestead\ C:\Users\[계정명]\Homestead\vagrant up C:\Users\[계정명]\Homestead\

=> 이때 /.ssh/id_rsa가 Not Found일때 : > ~/.ssh/ssh-keygen 실행

$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/[계정명]/.ssh/id_rsa): /c/Users/[계정명]/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again:

=> 동시에 C:\Users\[계정명]\VirtualBox VMs에 폴더가 Homestead-xx 생긴다.

=> Console , userid/password : vagrant/vagrant

=> destroy시 : > vagrant destroy --force

=> SSH auth에서 에러 발생시, 아래 config.ssh.forward_agent = true를 Vagrantfile내에 추가

(6) Vagrant ssh 실행

C:\Users\[계정명]\Homestead\ C:\Users\[계정명]\Homestead\vagrant ssh C:\Users\[계정명]\Homestead\

=> 접속 실패시

1) config.ssh.forward_agent = true를 Vagrantfile내에 추가

Vagrant.configure("2") do |config| config.ssh.private_key_path = "~/.ssh/id_rsa" config.ssh.forward_agent = true end

2) id_rsa.pub 복사

~/.ssh/id_rsa.pub@guest 파일 내용을 ~/.ssh/authorized_key@host에 추가

참조 : http://stackoverflow.com/questions/22922891/vagrant-ssh-authentication-failure

=> 추가로 다중 프로젝트(Laravel 어플리케이션) 생성하기

> vagrant ssh > cd Code > laravel new example #수정하기 #./homestead/Homestead.yaml sites: - map: homestead.app to: /home/vagrant/Code/Laravel/public - map: example.app to: /home/vagrant/Code/example/public databases: - homestead - example

==> 원문 :

https://laravel.com/docs/5.1/homestead

Homestead environment ( Port Forward , 충돌시 변경되므로 부팅 로그를 확인) :

SSH: 2222 → Forwards To 22

HTTP: 8000 → Forwards To 80

HTTPS: 44300 → Forwards To 443

MySQL: 33060 → Forwards To 3306

Postgres: 54320 → Forwards To 5432

==> 참고:

https://goo.gl/lRnC8k ( vagrant로 node 개발 환경 구성 하기 )

http://mobicon.tistory.com/322 ( vagrant 개발 환경 구축 및 애플리케이션 공유하기 )

--> Node.js + MongoDB 개발환경

http://l5.appkr.kr/lessons/02-install-homestead-windows.html

( Homestead 설치 (on Windows) )

--> SSH 설정, MySQL 접속(id/pw: homestead/secret)

http://m.blog.naver.com/two4zero/220602350718 ( laravel - Homestead 설치 )

http://k-story.tistory.com/333 (VirtualBox에서 xshell 연동하기.)

--> Virtual Box 네트워크 어댑터, 포트 포워딩 설정 ( 호스트 IP, 게스트 IP )

http://stackoverflow.com/questions/29450404/is-there-a-default-password-to-connect-to-vagrant-when-using-homestead-ssh-for ( 연결에 사용되는 default password )

--> vagrant@127.0.0.1's password:

* 기타 설치 에러 A:

Q : VBoxManage.exe hostonlyif create에러가 발생 할때

C:\Program Files\Oracle\VirtualBox\>VBoxManage.exe hostonlyif create 0%... Progress state: E_FAIL VBoxManage.exe: error: Failed to create the host-only adapter VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (extended info not available) VBoxManage.exe: error: Context: "int __cdecl handleCreate(struct HandlerArg *,int,int *)" at line 66 of file VBoxManageHostonly.cpp

Answer 1 : kaspersky 언인스톨, NDIS6 브릿지 드라이버 설청

Hi, I found a solution preventing you to uninstall Kaspersky. You have to install manually the VirtualBox Network drivers. You can found those drivers here : C:\Program Files\Oracle\VirtualBox\drivers

etwork There is two folders, go inside both of them and right click install on the *.inf files. Now the installation of hosts only virtual networks adapters should be nice but don't boot up. You have to manually install a new service on your "VirtualBox Host-Only Network" adapter. go to the network adapters list right click on this network adapter choose "Properties" click on the "Install..." button and add a service choose The Manufacturer "Oracle Corporation" and the network service named "VirtualBox NDIS6 Bridged Networking driver". Validate all the windows, and all should be OK.

Answer 2 : 네트웍 설정 ( Virtual Box )을 아래와 같이 수정

https://www.virtualbox.org/ticket/14040

* ssh-config 확인하는 방법

> vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile "/Users/MYUSER/.vagrant.d/insecure_private_key" IdentitiesOnly yes LogLevel FATAL ForwardAgent yes

* 기타 설치 에러 B:

Q : Warning: Authentication failure. Retrying...이 지속적으로 발생할때

==> default: Forwarding ports... default: 80 => 8080 (adapter 1) default: 22 => 2222 (adapter 1) ==> 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: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying... default: Warning: Authentication failure. Retrying...

실제 해결된 방법은 config.ssh.forward_agent = true를 Vagrantfile내에 추가하면 되었다.

Answer 1 : NAT -> Advanced 설정

http://stackoverflow.com/questions/40968297/laravel-homestead-hangs-at-ssh-auth-method-private-key-on-mac

Answer 2 : config.vm.boot_timeout = 600 을 추가하기

http://es.stackoverflow.com/questions/36242/error-config-vm-boot-timeout-en-vagrant-up-para-homestead

-- config.vm.boot_timeout = 600 ( Vagrantfile내에 추가 )

config.vm.boot_timeout = 600 if File.exist? homesteadYamlPath then settings = YAML::load(File.read(homesteadYamlPath)) elsif File.exist? homesteadJsonPath then settings = JSON.parse(File.read(homesteadJsonPath)) end

Answer 3 : private key를 host 등록하기

https://github.com/mitchellh/vagrant/issues/5186

0. vagrant ssh-config를 통해 IdentifyFile위치 확인 insecure_private.key.pub 내용 복사

$ vagrant ssh-config

Host default

HostName 127.0.0.1

User vagrant

Port 2222

UserKnownHostsFile /dev/null

StrictHostKeyChecking no

PasswordAuthentication no

IdentityFile C:/Users/admin/.vagrant.d/insecure_private_key

IdentitiesOnly yes

LogLevel FATAL

ForwardAgent yes

1. vagrant up중에 default: Warning: Authentication failure. Retrying...반복시에 중단

2. vagrant ssh접속 시도, passsword를 입력요청시에 vagrant를 입력

3. insecure_private.key.pub를 복사해서 ~/.ssh/authorized_keys에 추가 4. vagrant halt후에 vagrant up --provision으로 재시작

<예제>

config.ssh.private_key_path = File.expand_path('~/.ssh/id_rsa') config.vm.boot_timeout = 600 if File.exist? homesteadYamlPath then settings = YAML::load(File.read(homesteadYamlPath)) elsif File.exist? homesteadJsonPath then settings = JSON.parse(File.read(homesteadJsonPath)) end

vagrant 실행 화면 ( 정상적인 상황 )

$ vagrant reload --provision ==> homestead-7: Attempting graceful shutdown of VM... homestead-7: Guest communication could not be established! This is usually because homestead-7: SSH is not running, the authentication information was changed, homestead-7: or some other networking issue. Vagrant will force halt, if homestead-7: capable. ==> homestead-7: Forcing shutdown of VM... ==> homestead-7: Checking if box 'laravel/homestead' is up to date... ==> homestead-7: Clearing any previously set forwarded ports... ==> homestead-7: Clearing any previously set network interfaces... ==> homestead-7: Preparing network interfaces based on configuration... homestead-7: Adapter 1: nat homestead-7: Adapter 2: hostonly ==> homestead-7: Forwarding ports... homestead-7: 80 (guest) => 8000 (host) (adapter 1) homestead-7: 443 (guest) => 44300 (host) (adapter 1) homestead-7: 3306 (guest) => 33060 (host) (adapter 1) homestead-7: 5432 (guest) => 54320 (host) (adapter 1) homestead-7: 22 (guest) => 2222 (host) (adapter 1) ==> homestead-7: Running 'pre-boot' VM customizations... ==> homestead-7: Booting VM... ==> homestead-7: Waiting for machine to boot. This may take a few minutes... homestead-7: SSH address: 127.0.0.1:2222 homestead-7: SSH username: vagrant homestead-7: SSH auth method: private key homestead-7: Warning: Authentication failure. Retrying... homestead-7: Warning: Authentication failure. Retrying... homestead-7: Warning: Authentication failure. Retrying... homestead-7: Warning: Authentication failure. Retrying... .... homestead-7: Warning: Authentication failure. Retrying... homestead-7: Warning: Authentication failure. Retrying... homestead-7: Warning: Authentication failure. Retrying... ==> homestead-7: Machine booted and ready! ==> homestead-7: Checking for guest additions in VM... homestead-7: The guest additions on this VM do not match the installed version of homestead-7: VirtualBox! In most cases this is fine, but in rare cases it can homestead-7: prevent things such as shared folders from working properly. If you see homestead-7: shared folder errors, please make sure the guest additions within the homestead-7: virtual machine match the version of VirtualBox you have installed on homestead-7: your host and reload your VM. homestead-7: homestead-7: Guest Additions Version: 5.1.10 homestead-7: VirtualBox Version: 4.3 ==> homestead-7: Setting hostname... ==> homestead-7: Configuring and enabling network interfaces... ==> homestead-7: Mounting shared folders... homestead-7: /vagrant => C:/Users/admin/Homestead homestead-7: /home/vagrant/Code => C:/Users/admin/Code ==> homestead-7: Running provisioner: file... ==> homestead-7: Running provisioner: shell... homestead-7: Running: inline script ==> homestead-7: Running provisioner: shell... homestead-7: Running: inline script ==> homestead-7: Running provisioner: shell... homestead-7: Running: inline script ==> homestead-7: Running provisioner: shell... homestead-7: Running: C:/Users/admin/AppData/Local/Temp/vagrant-shell20170103-6508-1tmfveg.sh ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Creating Site: homestead.app ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Creating Site: example.app ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Restarting Nginx ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Creating MySQL Database: homestead ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Creating Postgres Database: homestead ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Creating MySQL Database: example ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Creating Postgres Database: example ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Clear Variables ==> homestead-7: Running provisioner: shell... homestead-7: Running: script: Update Composer ==> homestead-7: Updating to version 1.3.0 (stable channel). ==> homestead-7: Downloading: Connecting... Downloadi ng: 100% ==> homestead-7: Use composer self-update --rollback to return to version 1.2.3 ==> homestead-7: Running provisioner: shell... homestead-7: Running: C:/Users/admin/AppData/Local/Temp/vagrant -shell20170103-6508-inqc9i.sh

from http://printhelloworld.tistory.com/74 by ccl(A)

댓글

이 블로그의 인기 게시물

[PHP] 라라벨 루멘 DB문서 자동화