Setup Homestead on Windows – Step by Step guide
Table of Content – Setup Homestead on Windows
- Step One – Downloading The Required Files
- Step Two – Install Composer
- Step Three – Download Oracle Virtual Box and Vagrant
- Step Four – Install Homestead on Windows 10
- Step Five – Generating and Setting up Homestead.yaml file
- Step Six: Adding your Laravel Site
- Step Seven: Configure .ENV File
- Step Eight: Configuring your Host File
- Step Nine: Start-Up our Virtual Machine
- Step Ten: Setup a Database for your new site
It can be a little overwhelming for new developers to set up a Laravel development environment and even more frustrating if you decide to use Homestead. In this article, I will walk you through the various process of downloading, installing, and setting up Homestead on windows. Setup Homestead on Windows – Step by Step guide
I have come across articles online with plenty complains, I will do my best to keep it really simple.
Step One – Downloading The Required Files to Setup Homestead on Windows
Here are the files we need to download and install on our machine, In this step, begin by getting these files downloaded to your machine.
Download and Install Php
- Click here to download . Homestead comes with Php pre-install but the catch is, you can’t install composer without PHP already installed on your machine.
- Make sure you download the PHP zip version that is label Thread Safe do not download Non Thread Safe
- Once Download, Move the file to your Local Disk (C:) or any place safe, right-click, and extract the file using Winrar.
- Open the extracted folder and copy the path to this directory
- Tap the windows button and search for environment, then click on Edit the system environment variables Note. it’s not Edit Environment Variables for your account.
- Now click on Environment Variables, Select Path under System Variables, and click on edit.
Click on New and paste the path to the php directory we copied earlier.
Click on ok, ok, and ok again. That’s it, you now have Php installed. An alternative is to use Xamp, Mamp, Wamp, or Laragon. I strongly recommend Laragon because it is much easier to use. Now open your terminal (cmd) and type php -v this should display the currently installed version of php. If cmd was already open, then close and reopen.
Step Two – Install Composer
Go to the official Composer website here and download composer. Installation of the composer in win 10 is strait forward, simply run the installer and Composer does all of the jobs for you. Open your terminal and type composer -v, this should display the current composer version and a list of available commands. If you don’t see this info then repeat the process of adding composer to the environment variables. Here is the path to your composer installation: C:\ProgramData\ComposerSetup\bin Simply Add this to your environment variable.
Step Three – Download Oracle Virtual Box and Vagrant
Proceed by installing both softwares and follow the on screen instructions.
Step Four – Install Homestead on Windows 10
Now we proceed to install homestead on windows 10 machine by cloning the repository. Open your terminal and run this code
git clone https://github.com/laravel/homestead.git ~/Homestead
After running the above code, you should have a folder name Homestead on your PC. Unless you change directors, the folder can be found at your Admin folder at C:\Users\STECHMAX\ if you don’t find the folder check for a folder with this symbol ~ open it.
Step Five – Generating and Setting up Homestead.yaml file
Here is how the default homestead.yaml file looks like
--- 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
Now lets begin making some changes to this file. On line 7 here
Homestead is requesting our SSH key, if you’ve not generated one yet then Download and install git, then open Git Bash and run this code. replace firstname.lastname@example.org with your own email address.
$ ssh-keygen -t rsa -b 4096 -C "email@example.com"
When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.
> Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]
When prompted to enter a passphrase, pick something unique
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
Go back to your Homestead.yaml file and make this changes
The default looks like this
authorize: ~/.ssh/id_rsa.pub keys: - ~/.ssh/id_rsa
Change this two lines to this
authorize: c:/Users/USERNAME/.ssh/id_rsa.pub keys: - c:/Users/USERNAME/.ssh/id_rsa
This tells Homestead where our ssh key is located. Note the lowercase for the drive letter. user c: and not C:
Now also make this changes:
folders: - map: ~/code to: /home/vagrant/code
folders: - map: c:/Laravel_Projects to: /home/vagrant/code
The first line – map: tells laravel where our projects are going to be stored, the second line refers to a directory that will be available when we boot up our Virtual Machine. This means, whatever is inside the Laravel_Projects directory will also be available in the code directory. The two folders are in sync. Feel free to change Laravel_Projects to any directory of your choice but not the lower case c: use c: and not C:
The next thing then is to setup our websites, so lets say you want to work on a client website title JohnDoe, here is how you add your website
sites: - map: johndoe.test to: /home/vagrant/code/johndoe/public
and if you need to work on more sites
sites: - map: website-one.test to: /home/vagrant/code/website-one/public - map: website-two.test to: /home/vagrant/code/website-two/public - map: website-three.test to: /home/vagrant/code/website-three/public
We are done configuring this file, you shouldn’t bother about everything else in this file.
Step Six: Adding your Laravel Site
And now we are going to add our website johndoe which we referenced in the configuration file.
- Open your terminal and cd into your projects directory, for me I will navigate into c:/Laravel_Projects
- Run this code
composer create-project --prefer-dist laravel/laravel johndoe
This will install a Laravel project with the name johndoe in the Laravel_Projects Directory.
Optional: If the above code is too long for you to remember, then run this code
composer global require laravel/installer
Now when next you need to start a new project, you simply run
Laravel new project-title
Step Seven: Configure .ENV File
Open the Env file located in your project directory (In this case johndoe) and configure these two values
The password can be anything of your choice and the username too can be change as will.
Step Eight: Configuring your Host File
You’ll find your hosts file here C:\Windows\System32\drivers\etc, open the file and add this line of code:
192.168.10.10 johndoe.test 192.168.10.10 website-one.test 192.168.10.10 website-two.test
Save and close the file. You must open this file as an Administrator else you wouldn’t be allowed to make changes. If you’re using sublime, then right click sublime and open as administrator.
Step Nine: Start Up our Virtual Machine
From your Homestead directory, run
and allow it to do its magic.
When its doen run
Vagrant ssh cd code cd johndoe
Step Ten: Setup a Database for your new site
Now type mysql and press enter, create your database and name it exactly as you’ve configured in the .ENV file.
Exit from mysql and run your migrations using the code below
php artisan migrate
Last Step: Laravel Documentation
Now you have it a step by step guide on how to Setup Homestead on Windows. Dont forget to reach back to the laravel documentation always