Recently, I have moved my blog over to Statamic, a flat file CMS. In this blog post I will show you how to setup a local development server on your Windows computer using Laravel Homestead.
First you will want to install VirtualBox and Vagrant. These will help us create a virtual machine so things like Nginx are not actually on the machine itself. It also means if you mess it up then you can re-create the VM in a matter of minutes.
Another thing you will need is Git Bash for Windows.
Now you have everything installed we can open Git Bash and copy this code in:
vagrant box add laravel/homestead
This adds the Laravel Homestead box to Vagrant.
In Git Bash, you can locate to your home directory or your chosen location for the VM.
cd C:\Users\YOUR USER NAME\
Then we can clone Homestead from GitHub.
git clone https://github.com/laravel/homestead.git Homestead
After it has been cloned, go into the Homestead directory and do
Before we create the box we need to generate an SSH keys.
cd C:\Users\YOUR USER NAME\
ssh-keygen -t rsa -C “email@example.com”
Now we are going to configure Homestead, to do so open the Homestead.yaml file which is located in the folder where we cloned the git repository to earlier. The file looks something like this:
— - 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 sites: — map: homestead.app to: /home/vagrant/Code/Laravel/public databases: — homestead / blackfire: / — id: foo / token: bar / client-id: foo / client-token: bar / ports: / — send: 50000 / to: 5000 / — send: 7777 / to: 777 / protocol: udp
There are a few things we are going to change. This is what my file looks like when it's complete.
— - ip: “192.168.10.10” memory: 1024 cpus: 1 provider: virtualbox authorize: c:/Users/YOUR USER NAME/.ssh/id_rsa.pub keys: — c:/Users/YOUR USER NAME/.ssh/id_rsa folders: — map: c:/statamic to: /home/vagrant/Code sites: — map: statamic.dev to: /home/vagrant/Code/statamic/public databases: — homestead / blackfire: / — id: foo / token: bar / client-id: foo / client-token: bar / ports: / — send: 50000 / / to: 5000 / — send: 7777 / to: 777 / protocol: udp
I've changed the location for my SSH keys, the location of my code and the domain I'm using. The disk letters need to be in lower case or they won't work.
Now we need to edit some driver files which we can find in C:\Windows\System32\Drivers\etc. The file we want to edit is called hosts. In my case, I had to edit the permissions so I could edit the file.
At the bottom of the file add the following.
These need to be the same as they are in the Homestead.yaml file we edited.
Now we can go back into the Git Bash terminal and cd into our VM location.
C:\Users\YOUR USER NAME\Homestead
Whilst in this directory, do the following command.
This will create your VM for the first time.
Now we have a fully functioning VM for our Statamic install. We can stop and start the machines using the following commands.
vagrant suspend Suspends the machine.
vagrant resume Resumes the machine.
The only problem now is that we don't actually have Statamic on the server. Just download it from the Statamic site, unzip it and copy the files to your Code directory.
Now you're complete