Search code examples
laraveldockerssllaravel-8laravel-sail

how do you enable ssl using laravel 8 sail


I just created a new Laravel 8 project, following the instructions in their docs. Using Laravel Sail I have the site running locally on my machine just fine using sail up. I have set up an entry in /etc/hosts so the url I go to is http://local.dev.domain.com (substituting domain.com for the actual domain name I own, and pointing to localhost in the /etc/hosts file)...all works great.

However, the site needs to use Facebook Login, and Facebook requires https urls only on referrers. I've tried everything I could find online about setting up SSL certs with docker, but setting up nginx with manually created certs (via mkcert) or trying to use letsencrypt all fails for various reasons (conflicts in ports, letsencrypting wanting the domain to be a real one (and failing on the acme challenge if I do create that subdomain), etc. I've copied the certs to /etc/ssl/certs in the docker image and run update-ca-certificates, tried setting the application port 443 in my .env file as well as opening both ports 80 and 443 in the docker-compose.yml file...but all ends in the browser rejecting the request to https://local.dev.domain.com

I've spent hours trying to get this to work but it doesn't seem like anyone has used the Laravel Sail docker image with SSL.

Any pointers?

[Edit for more info] As pointed out in the comments, you need to set an alias to just use sail ..., but I've already done that:

enter image description here

I also tried without the bash alias using vendor/bin/sail share to no avail:

enter image description here


Solution

  • Problem

    In your case you need a real domain, which you have. A self-signed certificate would not work as Facebook would not acknowledge it as trusted. To get a free ssl certificate for that domain you can use Let's Encrypt, the easiest way to obtain that certificate is using certbot. The problem is that you need to install that certificate on your webserver. Laravel Sail uses the build-in webserver that does not support ssl unfortunatly. You need to put a webserver like nginx in front of the app and install the certificate there.

    I'm currently working on a fork that enables what you need, however it's not finished.

    Workaround

    For now you can use the build in tunnel provided by Expose: https://beyondco.de/docs/expose/server/ssl

    This is enable by sail share

    It might be easier to use ngrok instead, which is essentialy the same but commercial. Than all you have to do is download, register and run ngrok http --region=eu 9000 and it will create a https link for you for development.

    enter image description here