DEV Community

Cover image for Installing Laravel Homestead on MacOS🔧
Ko Takagi
Ko Takagi

Posted on • Edited on

Installing Laravel Homestead on MacOS🔧

Laravel Homestead is official local development environment.
It is a great tool that allows you to easily create an environment with all the functions required for development.

The following is the steps for installing Laravel 6.x on MacOS with Homestead.

Install VirtualBox.

Install Vagrant.

Install the Homestead Vagrant box.

$ vagrant box add laravel/homestead
Enter fullscreen mode Exit fullscreen mode

By the way, if you couldn't install homestead above command, you can use the following:

$ vagrant box add laravel/homestead https://vagrantcloud.com/laravel/homestead 
Enter fullscreen mode Exit fullscreen mode

Install Homestead.

$ git clone https://github.com/laravel/homestead.git ~/Homestead
Enter fullscreen mode Exit fullscreen mode

Create the Homestead configration file.

$ cd ~/Homestead
$ bash init.sh
Enter fullscreen mode Exit fullscreen mode

Homestead.yaml is created in the directory.

$ cat Homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/code
      to: /home/vagrant/code

sites:
    - map: homestead.test
      to: /home/vagrant/code/public

databases:
    - homestead

features:
    - mariadb: false
    - ohmyzsh: false
    - webdriver: false

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp
Enter fullscreen mode Exit fullscreen mode

View the folders property of the Homestead.yaml file.

folders:
    - map: ~/code
      to: /home/vagrant/code
Enter fullscreen mode Exit fullscreen mode

Create directory according to settings.

$ mkdir ~/code
Enter fullscreen mode Exit fullscreen mode

Edit the sites property of the Homestead.yaml file. In the case, the project directory name is myproject.

sites:
    - map: homestead.test
      to: /home/vagrant/code/myproject/public
Enter fullscreen mode Exit fullscreen mode

Add name resolution to hosts file.

$ sudo vi /etc/hosts

192.168.10.10 homestead.test
Enter fullscreen mode Exit fullscreen mode

Launch Vagrant.

$ cd ~/Homestead
$ vagrant up
Enter fullscreen mode Exit fullscreen mode

If there are not id_rsa (secret key) and id_rsa.pub (public key) in ~/.ssh directory, create key files.

$ ssh-keygen -t rsa
Enter fullscreen mode Exit fullscreen mode

Connect to virtual machine using SSH.

$ vagrant ssh
Enter fullscreen mode Exit fullscreen mode

Install Laravel with project name myproject.

$ cd ~/code
$ composer create-project --prefer-dist laravel/laravel myproject
Enter fullscreen mode Exit fullscreen mode

View homestead.test in your browser.

Welcome to Laravel

Good Job!👍

Top comments (6)

Collapse
 
secmohammed profile image
mohammed osama

in case you couldn't install homestead using

vagrant box add laravel/homestead 

you can use the following :

vagrant box add laravel/homestead https://vagrantcloud.com/laravel/homestead 
Collapse
 
ko31 profile image
Ko Takagi

Thanks for your reply! I added your command to this article.

Collapse
 
didikz profile image
Didik Tri Susanto

Nice tutorial, more straightforward step and easy to follow.

Collapse
 
ko31 profile image
Ko Takagi

Thanks a lot!

Collapse
 
macelux profile image
MacDonald Chika

Nice tutorial but you missed the OS X permission issue steps.

Collapse
 
parthparmar7 profile image
Parth

can you elaborate on that please?
I have this issue when using vagrant with virtualbox
`
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'aborted' state. Please verify everything is configured
properly and try again.

If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run vagrant up while the
VirtualBox GUI is open.

The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.`