DEV Community

Nikolas Evers
Nikolas Evers

Posted on β€’ Originally published at nikol.as on

9 5

How to setup HTTPS with Laravel Homestead on a Windows host

This guide assumes prior experience with Vagrant and Laravel Homestead.

Laravel Homestead is an easy-to-use Vagrant box for local Laravel development, but getting SSL to work on a Windows host can be tricky if you've never done it before. This guide will show you how to enable SSL and how to trust the certificate in Firefox.

Prerequisites:

Let's create a new Laravel project for demonstration purposes:

composer create-project --prefer-dist laravel/laravel ssl-example
Enter fullscreen mode Exit fullscreen mode

Now we need to configure a Homestead instance for our project:

cd ssl-example
composer require laravel/homestead --dev
vendor\\bin\\homestead make
Enter fullscreen mode Exit fullscreen mode

You should see the following output in your console:

Homestead Installed!
Enter fullscreen mode Exit fullscreen mode

Edit Homestead.yaml and make the following changes:

-       map: homestead.test
+       map: laravel.localhost
        to: /home/vagrant/code/public
+ ssl: true
Enter fullscreen mode Exit fullscreen mode

Note: Feel free to change laravel.localhost throughout the guide to a local domain of your choice.

Your Homestead.yaml should now look similar to this:

ip: 192.168.10.10
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
    - ~/.ssh/id_rsa
folders:
    -
        map: 'D:\Documents\GitHub\ssl-example'
        to: /home/vagrant/code
sites:
    -
        map: laravel.localhost
        to: /home/vagrant/code/public
databases:
    - homestead
name: ssl-example
hostname: ssl-example
ssl: true
Enter fullscreen mode Exit fullscreen mode

Add the following line to C:\Windows\System32\drivers\etc\hosts:

Note: The IP address should match Homestead.yaml

192.168.10.10 laravel.localhost
Enter fullscreen mode Exit fullscreen mode

Install the Homestead Vagrant Box:

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

Let's start our Vagrant box:

vagrant up
Enter fullscreen mode Exit fullscreen mode

If you are using this guide to add SSL to an existing VM, use this command instead:

vagrant reload --provision
Enter fullscreen mode Exit fullscreen mode

Wait until the provisioning process has been completed.

You should now be able to visit http://laravel.localhost in your browser:

Laravel over HTTP

Now we need to get the CA certificate from the VM:

vagrant ssh -c 'cat /etc/nginx/ssl/ca.homestead.ssl-example.crt' > ca.homestead.ssl-example.crt
Enter fullscreen mode Exit fullscreen mode

Note: Change ssl-example to match your Homestead.yaml.

You should now have ca.homestead.ssl-example.crt inside your ssl-example folder.

In Powershell, as admin, run the following command to add the certificate to the certificate store:

certutil -addstore -enterprise -f "Root" ca.homestead.ssl-example.crt
Enter fullscreen mode Exit fullscreen mode

Note: You can now remove ca.homestead.ssl-example.crt from the ssl-example folder.

Last but not least, we need to get Firefox to trust the certificate.

In Firefox, navigate to about:config. Read this introduction if your unfamiliar with the Configuration Editor for Firefox.

Set security.enterprise_roots.enabled to true and restart Firefox.

You should now be able to visit https://laravel.localhost in your browser.

Laravel over HTTPS

Congratulations! πŸŽ‰

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
fromchiapasdev profile image
Axel Espinosa β€’

This really helped me, thanks

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️