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

Finding Valet configuration0:00

Valet, like most of Laravel, comes pre-configured out of the box with the most reasonable way to do things. We call this convention over configuration. But every time you run valet park, valet link, valet secure, or anything else that customizes your particular instance of Valet for one site or one folder, you're doing configuration, but that's perfectly okay. In this episode, we're going to take a look at where that configuration happens so you can have a better understanding of what actually powers your Valet. Valet's configuration files and folders live in your home directory under .config/.valet. The first and simplest place to look for configuration details is the config.json file.

Understanding config.json paths0:30

Valet's configuration files and folders live in your home directory under .config/.valet. The first and simplest place to look for configuration details is the config.json file. By default, you'll only have three items in here, tld, loopback, and paths. Let's dig into each of these really quickly. First we'll look at paths, since it's the configuration most likely to change. This paths config item is where Valet looks to find all directories it should treat as sites. So if I go to my sites directory, and run valet park, you'll see that my sites directory is in here in this array. So that means every time Valet tries to resolve a .test URL, it'll try to find a folder in

is in here in this array. So that means every time Valet tries to resolve a .test URL, it'll try to find a folder in there that matches. Anytime you've parked any folders, they'll all live here. But sometimes you might also see another directory in here that lives in the config.json folder that we're in right now. What is it? First, let's take a look at the directory I'm talking about. As you can see in here, there's a sites directory. And so some folks might see tld.configs.valet.sites as one of the entries in their config.json

How valet link works1:25

As you can see in here, there's a sites directory. And so some folks might see tld.configs.valet.sites as one of the entries in their config.json paths section. Well, that's because every time you use valet link, what it's really doing is creating a symlink from the folder that you're linking into this directory we're looking at right now. And that's how it actually adds it to the list of potentially resolvable URLs at this new symlinked name. I know that's a little bit hard to follow, so let's take a closer look. If I was working in one of my sites, let's say the Floga site, right now, if sites is

I know that's a little bit hard to follow, so let's take a closer look. If I was working in one of my sites, let's say the Floga site, right now, if sites is parked, this will be accessible as floga.test. But what if I want it to be accessible as something else? I've done valet link, Poga. So it feels like there might be some kind of magic going on here that makes that link work. But look at the notes there. A Poga symbolic link has been created in tld.configs.valet.sites.ploga. So what's really happening here is in that configs.valet.sites directory is literally

A Poga symbolic link has been created in tld.configs.valet.sites.ploga. So what's really happening here is in that configs.valet.sites directory is literally just a system-level symlink that says, hey, if you are looking at this tld.configs.valet.sites folder, treating it as a parked folder, then if you are looking at Poga.test, it should serve from where? tld.sites.floga. So Valet Link is purely just creating symlinks in this directory and then double-checking our config.json to make sure that directory shows up. So if we do take a look at our config.json now, we'll notice that that particular directory that was not there earlier has now shown up.

Configuring loopback and TLD2:52

So if we do take a look at our config.json now, we'll notice that that particular directory that was not there earlier has now shown up. So if you ever see this here, that's what it's for. This is just a magic little directory that Valet creates to manage symlinks. Clever. All right, let's talk about the loopback next. The loopback is something I don't see people change very often. I want to explain really quickly what a loopback address is. A loopback address is any IP address in the range from 127.0.0.1 all the way up to 127.255.255.255. What this means is any number between 0 and 255 for the second place, any number between

A loopback address is any IP address in the range from 127.0.0.1 all the way up to 127.255.255.255. What this means is any number between 0 and 255 for the second place, any number between 0 and 255 for the third place, and any number between 0 and 255 for the fourth place. So any of those are called loopbacks. And what that means is any requests made to this IP address from your computer will never actually go out to the internet. They'll loop back and just be processed by your computer. The most common loopback address is 127.0.0.1, which you may be familiar with as localhost. This address is mainly used for testing web applications and networks. By default, Valet uses 127.0.0.1 as its loopback address, but if you wanted, you could change

This address is mainly used for testing web applications and networks. By default, Valet uses 127.0.0.1 as its loopback address, but if you wanted, you could change to a different one. From what I understand, the most common use case for this is if you want your Docker sites to be able to connect to your Valet sites. If you're doing this, you'd run valet loopback and then your new loopback IP address, and it would just change it right here in config.json, as well as updating some other configuration settings elsewhere in your computer. And finally, let's cover the TLD. It's something that we used to make easier to change in Valet, and there still is a valet-tld.

And finally, let's cover the TLD. It's something that we used to make easier to change in Valet, and there still is a valet tld command that allows you to change the TLD, but it gives you a warning when you try it. If you try anything other than .test, things can go wrong in weird ways, so I'd recommend that only Power users very familiar with Valet change their TLD. One of the reasons for this is we used to use all sorts of other domains like .dev, but Google and other providers have slowly rolled out those TLDs, and you don't want to use a TLD for Valet that is actually a real live TLD. By the way, if you're unfamiliar with what TLD means, it's a top-level domain, which means it's everything that goes at the end of your domain, so www.whatever.test.

Other config.json options4:44

By the way, if you're unfamiliar with what TLD means, it's a top-level domain, which means it's everything that goes at the end of your domain, so www.whatever.test. So if I change my TLD to mat, all of my Valet sites would be served at whateverwhateverwhatever.mat. There are other potential configuration items that can live in this file. Some are managed by configuration tools, some of them you'll only ever update them manually. There's three main ones that you should know about. The first one is share-tool, and if you haven't seen the episode about using Valet share, go check it out, but your share-tool value will be set to either expose or ngrok. There's directory-listing, which determines whether or not empty directories will be shown. I'll show you that in just a second.

There's directory-listing, which determines whether or not empty directories will be shown. I'll show you that in just a second. And then there's logs, which allows you to find custom log files that you want the valet-logs command to watch, which we'll take a look at in a later episode. Let me show you directory-listing really quickly. So if we write valet directory-listing, it's going to tell you what the value is right now. And by default, even if it's not set in config.json, it's off. And what that means is, if we go to an app that is just files and directories, not actually an index.html or an index.php or something like that, for example, my.has-directories.test

And what that means is, if we go to an app that is just files and directories, not actually an index.html or an index.php or something like that, for example, my has-directories.test folder I have, you're just going to get a 404, because by default, it's looking for actual files that are meant to serve a website, index.html, index.php. But some people have said they like to use Valet to just show a list of their directories. So if you write valet directory-listing on, and you come back here, you're now suddenly going to see those directories. And in those directories, you're going to see their subdirectories, so you can navigate through them. It's not a super fully fleshed out feature, but some people seem to really like it.

through them. It's not a super fully fleshed out feature, but some people seem to really like it. So if we take a look at our config.json, we will now see directory-listing set, and it's set to on. And if you wanted, you could come in here and edit it manually, although I wouldn't recommend doing a lot of editing in here manually, just because it's kind of easy to mess up the JSON syntax. But if we do edit it manually there, and we come back, 404 again. Finally, let's cover all the rest of the files and folders that are inside this config.json Valet folder.

Touring Valet config folders6:32

Finally, let's cover all the rest of the files and folders that are inside this config.json Valet folder. First thing is CA. CA is just the certificate authority. The certificate authority is basically the thing that Valet uses to say, hey, I'm able to give out SSL certificates for these sites. Normally, the only certificate authorities that you can work with are ones that the browser makers actually trust. Because we're working locally, Valet says, hey, just trust me, I'm making these certificates. It's only going to work on our local machine.

Because we're working locally, Valet says, hey, just trust me, I'm making these certificates. It's only going to work on our local machine. Certificates is where the actual certificates live. So if we were to go to the certificates directory and list it out, we would see all the files that are needed to provide an SSL certificate to the browser for every single site that we've secured. The next directory to take a look at is the drivers directory. All the drivers that Valet provides by default are hidden in Valet's vendor files. So this directory only contains the drivers that you've specifically made. And as you can see, a new Valet installation comes with a sample Valet driver that you

So this directory only contains the drivers that you've specifically made. And as you can see, a new Valet installation comes with a sample Valet driver that you can use to make your own. But in general, nothing's going to be in here unless you put it here. The log folder is where Valet has pointed at some of its dependencies to specifically point their logs so it's easier for you to find them. Now with Valet, every single site that you're serving, just like with Forge or anything else that's using Nginx, has its own custom configuration file that defines how to serve it. But with Valet, that configuration file is basically exactly the same for all sites.

it. But with Valet, that configuration file is basically exactly the same for all sites. So there's one default it uses for everything else, but if you ever need to customize your configuration for any particular site, and one of the reasons you may have to do that is because you secured it. Because once you secure a site, it has to point to its custom SSL certificate. It's also going to get customized if you have a specific version of PHP. As we talked about before, the sites directory is anytime you use valet link. The DNS mask directory contains any specific DNS mask configuration files that you put in yourself.

The DNSMasq directory contains any specific DNSMasq configuration files that you put in yourself. For most folks, you're only ever going to see tld-test.conf, and here you can see at one point when I was doing some work on Valet 4, I tried .buzz as a TLD just to make sure that all those features were working. If you want to put in custom configuration items for your own DNSMasq, you can. Just throw them in here with a filename ending with .conf, and DNSMasq will pick them up. And finally, the .soc files. Socket files are essentially pointers that programs on your computer use to connect to each other.

Socket files are essentially pointers that programs on your computer use to connect to each other. They're sort of like IP addresses on your internal machine. The files themselves don't actually contain any data. They're just pointers that these programs use to send data back and forth to each other. So these particular pointers are used to basically connect php FDM with Nginx. So hopefully seeing all those configuration files and folders helps you understand a little bit of how Valet actually works behind the scenes and demystifies it a little bit. Obviously, you don't want to be in those folders and files doing a lot of manual stuff all the time, but I'm really hoping that just understanding where that configuration lives.

Obviously, you don't want to be in those folders and files doing a lot of manual stuff all the time, but I'm really hoping that just understanding where that configuration lives and what those files and folders actually do for you will help you feel more confident in knowing what Valet does, how to work with it, and how to troubleshoot it.

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