در حال بارگذاری ...

Securing a Site0:00

One of the benefits of using Valet over a simpler tool like PHP's built-in hosting is that we can secure our local development sites. With a single command, valet secure, we can take our existing http://floga.test site and turn it into https://floga.test. Let's take a look. So let's check our site in the browser at floga.test. As you can see, it's not secured, and we're running it on HTTP, not on HTTPS. If we do try to visit the HTTPS version, we're going to just get an error saying it can't connect to the site. So let's open up our terminal to the folder for floga and run valet secure.

connect to the site. So let's open up our terminal to the folder for floga and run valet secure. This should pop up a prompt saying you're making changes to the system certificate trust settings. That's a sign you're doing it right. We've built a certificate for the site, and now we're telling our system to trust it. Once this is done and we visit the domain in our browser, we'll automatically be redirected to the HTTPS version of the site. And that's all you have to do to secure a site with valet. If you want to update the site to make it not secured anymore, you can just run valet.

Using Unsecure and Certs1:01

And that's all you have to do to secure a site with valet. If you want to update the site to make it not secured anymore, you can just run valet unsecure, and it'll undo everything we just did to secure it. If you're like me, you're probably curious about that certificate I mentioned earlier that we told the system to trust. Where did it come from? Where does it actually live? Well, let's take a look real quickly at just where those files are. So first we've got to re-secure our site, and then we can head over to the valet config directory.

Finding Certificate Files1:24

So first we've got to re-secure our site, and then we can head over to the valet config directory. And here we'll see a certificates folder, and you can see four files here that constitute the certificate for floga.test. If you ever worked with custom SSL certs before the days of Let's Encrypt, this will be super familiar to you. So this is where everything lives. And when valet sets this all up, it's actually informing our machine, hey, the certificate authority that I've created should include this particular floga.test SSL cert. And so if anybody tries to hit the HTTPS version of that site, take a look here for a valid

Securing Subdomain Aliases1:57

authority that I've created should include this particular floga.test SSL cert. And so if anybody tries to hit the HTTPS version of that site, take a look here for a valid certificate. Now let's unsecure it. Now it's an empty directory. If you also set up a linked alias to your site, for example, the subdomain we set up earlier, which was bary.floga, you can secure that subdomain by passing the subdomain and the domain, but not the TLD to the valet secure command. So if we've got bary.floga.test as a linked subdomain, we can run valet secure bary.floga, and now that specific subdomain will be secured in the browser.

So if we've got bary.floga.test as a linked subdomain, we can run valet secure bary.floga, and now that specific subdomain will be secured in the browser. And there we go. At any point, you can run valet secured to see a list of all the sites you've currently secured with valet. If you want to unsecure any of your secured sites, you can just run valet unsecure and then the domain from anywhere else on your machine. One interesting aspect of securing your sites through valet is that you can secure sites and see whether your sites are secured through other portions of valet. So if you're linking a site, and remember that's when you're manually attaching a given

Secure While Linking3:24

and see whether your sites are secured through other portions of valet. So if you're linking a site, and remember that's when you're manually attaching a given domain or subdomain to a folder, you can also pass the --secure flag to secure it as you link it. So let's try admin.floga and secure it as we go. And there you go, linked and secured at the same time. Accordingly, you can also see whether a site is secure or not when you're running valet links to see all your links. You can take a look at the SSL column here to see, although because I have my font size turned up for recording, this table doesn't work super well.

You can take a look at the SSL column here to see, although because I have my font size turned up for recording, this table doesn't work super well. You can also see which sites are secured when you're taking a look at all the sites that are served based on being parked. If we look at valet parked, we can see how it displays the secure status in the column as well. So if I were to go over to my new site, run valet secure, and then run valet parked again, you'll now see an X in that SSL column showing that it's been secured. We haven't talked about proxies at all yet, but you can also secure a site as you register a proxy.

Secure Status in Valet4:38

We haven't talked about proxies at all yet, but you can also secure a site as you register a proxy. And if you list all your proxies with the valet proxies command, you'll see a column here for whether or not secure as well. Securing your sites in valet is one of those features that makes valet really shine. There's not a lot of nuance to actually using this feature, but this functionality is very difficult to pull together by hand in traditional hosting environments. And as you can see, it's a total snap in valet.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟