INtelligent Dev: Adding a Let’s Encrypt SSL to Laradock
Every site should be encrypted. Period. With Let’s Encrypt as a free Certificate Authority, there is no longer a valid excuse to fail to encrypt your site’s data at even its most basic level. And if your production site’s traffic is encrypted, your development site should be as well to help ease the testing process. So let’s get started. It will only take a couple of minutes.
The only downside to using Laradock with SSL is that you are forced to use Caddy instead of Nginx. For me, that is not an issue. If it is for you, hopefully the developers at Laradock will have a solution sometime soon.
The first step is to edit the ‘Caddyfile’ in your ‘laradock’ folder:
On the second line replace 0.0.0.0:80 with your domain:
Next you will want to uncomment the following line and replace ‘self_signed’ with your email address:
Now you need to bring Docker up at the command line:
docker-compose up caddy
Note that I did not use the ‘-d’ flag to run Docker in daemon mode.
Your Docker instance will communicate with the Let’s Encrypt server (it will prompt you for your email), build the certificate for you, and then install it.
Attaching to laradock_mysql_1, laradock_caddy_1
caddy_1 | Activating privacy features...
caddy_1 | Your sites will be served over HTTPS automatically using Let's Encrypt.
caddy_1 | By continuing, you agree to the Let's Encrypt Subscriber Agreement at:
caddy_1 | https://letsencrypt.org/documents/LE-SA-v1.0.1-July-27-2015.pdf
caddy_1 | Activating privacy features... done.
caddy_1 | https://yourdomain.com
caddy_1 | http://yourdomain.com
Press ctrl+C to quit the process. Then bring Docker down:
Then you can bring up Docker and run it in the background:
docker-compose up -d mysql caddy
That is all there is to it. You should now be able to browse to https://www.yourdomain.com.