Homestead Vagrant box
Once VirtualBox and Vagrant have been installed, we should add the laravel/homestead box.
The following command installs the Homestead box which is a Vagrant package. The package is a virtual machine image that contains the operating system and various programs.
$ vagrant box add laravel/homestead
We may want to install the Homestead by simply cloning the repository into a Homestead folder within our "home" directory:
$ cd ~ $ git clone https://github.com/laravel/homestead.git Homestead $ cd Homestead/ $ ls composer.json composer.lock homestead init.bat init.sh LICENSE.txt readme.md scripts src Vagrantfile $ bash init.sh Homestead initialized!
Homestead configuration file is ~/.homestead/Homestead.yaml.
The file has the following configurations:
--- ip: "192.168.10.10" memory: 2048 cpus: 1 provider: virtualbox authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa folders: - map: ~/Code to: /home/vagrant/Code # type: "nfs" sites: - map: homestead.app to: /home/vagrant/Code/Laravel/public # hhvm: true databases: - homestead ...
To redirect any requests for our Homestead sites into our Homestead machine, we need to add the ip to /etc/hosts.
192.168.10.10 homestead.app
Once we have added the domain to our hosts file, we can access the site via a web browser:
http://homestead.app
Now that we have edited the Homestead.yaml, let's run the vagrant up command from our Homestead directory where the Vagrantfile exists. Vagrant will boot the virtual machine and automatically configure our shared folders and Nginx sites.
Before running the Vagrant, I usually clean-up any left over from previous runs using vagrant halt:
k@laptop:~/Homestead$ vagrant box list laravel/homestead (virtualbox, 0.4.1) ... k@laptop:~/Homestead$ vagrant halt
Now, let's run it :
k@laptop:~/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 forwarded ports... ==> 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: 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: Setting hostname... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => /home/k/Homestead default: /home/vagrant/Code => /home/k/Code ==> default: Running provisioner: file... ==> default: Running provisioner: shell... default: Running: inline script ==> default: ssh-rsa H1VlkCqVt8c7jSd9ijmCumk@laptop ==> default: Running provisioner: shell... default: Running: inline script ==> default: Running provisioner: shell... default: Running: /tmp/vagrant-shell20160211-16327-1ywveu1.sh ==> default: Running provisioner: shell... default: Running: /tmp/vagrant-shell20160211-16327-nyun0y.sh ==> default: nginx stop/waiting ==> default: nginx start/running, process 1973 ==> default: * Restarting PHP 7.0 FastCGI Process Manager php-fpm7.0 ==> default: ...done. ==> default: Running provisioner: shell... default: Running: /tmp/vagrant-shell20160211-16327-u8q59u.sh ==> default: mysql: ==> default: [Warning] Using a password on the command line interface can be insecure. ==> default: Running provisioner: shell... default: Running: /tmp/vagrant-shell20160211-16327-117yu2w.sh ==> default: createdb: database creation failed: ERROR: database "homestead" already exists ==> default: Running provisioner: shell... default: Running: /tmp/vagrant-shell20160211-16327-1oqcy1h.sh ==> default: Running provisioner: shell... default: Running: inline script ==> default: You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug ==> default: Updating to version 6d1ebba75e99b8c714112bc85e96591ee0fdf0b4. ==> default: Downloading: Connecting... ==> default: ==> default: Downloading: 100% ==> default: Use composer self-update --rollback to return to version 837fa805ec9f8dcb1e05e0fca4099f0dab4f1e04 ==> default: Running provisioner: shell... default: Running: /tmp/vagrant-shell20160211-16327-cy2pas.sh
ssh into Homestead Vagrant box:
k@laptop:~/Homestead$ ssh vagrant@127.0.0.1 -p 2222 vagrant@homestead:~$
To destroy the machine, we can use the vagrant destroy --force command.
For more information about vagrant, please visit Creating a VirtualBox and using Vagrant.
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization