Develop web app using Laravel Homestead and Vagrant

Victor Yeo
2 min readOct 29, 2020

--

Vagrant is a virtual machine setup and configuration tool from Hashicorp. (Vagrant requires the use of VirtualBox or VMware.) Laravel Homestead is an official Vagrant box that provides a development environment so that you do not have to install PHP, MySQL and web server on your local machine. Does it sound great? Now let’s go to the details. The following steps are carried out on Ubuntu 20.04.

  1. Firstly, create a Laravel project. I install Laravel command line tool so that i can use laravel command to create a project.

composer global require laravel/installer

add the line below to .bashrc

export PATH=$PATH:$HOME/.config/composer/vendor/bin

laravel new mylara; cd mylara

2. Install Homestead on the project

composer require laravel/homestead --dev

After that, open up composer.json and check that homestead is in dev dependencies

3. Generate Vagrantfile and Homestead.yaml

./vendor/bin/homestead make

Vagrantfile is a Ruby file that describes how to configure and provision the VM.

4. Map the URL of the project

Inspect Homestead.yaml, search for “sites:”, the map line contains the url of the project. In the attached picture below, the map line is homestead.test.

Then go to /etc/hosts and add the line:

192.168.10.10. homestead.test

5. Run the vm

vagrant up

The command above will download the correct Vagrant box, it will take some time. To shorten the time, do the command below to add homestead to the Vagrant box:

vagrant box add laravel/homestead

6. Connect VM with SSH

vagrant ssh

You may have to generate a key with

ssh-keygen -t rsa -C <email_address>

6. View the web app in the browser

Go to browser address bar, and type homestead.test

7. Modify the project files in Laravel Homestead

After you ssh to the vagrant box, do “cd code”, you will see the project files. For example, modify the file :

resources/views/welcome.blade.php

save the file, reload the browser. You will see the changes.

If you notice any errors, please do not be hesitated to contact me.

--

--

Responses (1)