Set up Laravel Homestead Development environment

Contents


Install PHP 7 and composer


This article assumes you have PHP 7 and composer installed. If not, you can install PHP7 via brew if you are on Mac and install composer globally by downloading composer.phar


1
2
3
brew update
brew install php@7.2
mv composer.phar /usr/local/bin/composer

Install virtual box and vagrant


You need to install virtual box and vagrant


Add vagrant box


When you add vagrant box, the version is quite important. I have experienced different kinds of errors just because of different version numbers. I have tested laravel/homestead 9.3.0 working ok with PHP 7.2


1
2
3
4
vagrant box add laravel/homestead --box-version 9.3.0

sudo -H composer self-update


create your project


1
2
3
4
5
6
composer create-project --prefer-dist laravel/laravel yourLaravelProject

cd yourLaravelProject/

composer require laravel/homestead --dev


Make the homestead file


On Windows


1
vendor\\bin\\homestead make

On Mac


1
php vendor/bin/homestead make

If you have “private key cannot be found” error, make sure you have private key in .ssh/ directory by typing below:


1
ssh-keygen -t rsa -f ~/.ssh/id_rsa

Add below line to Homestead.yaml


version: 9.3.0


Build vagrant box


1
vagrant up

Get into the box


1
2
3
4
5
vagrant ssh
cd code 
sudo nano /etc/hosts
# add below line to the file 
192.168.10.10   homestead.test 

Now you can go to homestead.test and see Laravel website is running!