Why .test Returns 4040:00
In the last episode, we talked about how Valet installed a tool called dnsmasq that intercepts all requests to domains that end in the .test TLD. That'll be helpful for us later, but right now, all of those requests just end up in a 404. So let's take a look at how to teach Valet to find our sites. When Valet and its dependencies are running, they tell our computer's internal DNS resolver, every time this user requests a .test domain, let me handle it. Then when that domain is requested, it runs through its internal list of sites it can serve to see if any of those sites match the given domain. By default, that list is empty, and that's why we're getting all 404s. Take a look at our site floga here, and all we get is a file not found or a 404. But we can change that right away. There are two ways we can teach Valet where
Using Valet Park0:36
getting all 404s. Take a look at our site floga here, and all we get is a file not found or a 404. But we can change that right away. There are two ways we can teach Valet where to look for our sites, valet park and valet link. Valet's park command is our way of saying every single subfolder under this folder that we're parking should be treated as a site. So it's the easiest way to get started using valet park today. Throw all your sites together in the same directory, park the directory, and then every single one of your sites will be accessible at foldername.test. We can park more than one directory, and we can even customize how some of the sites are served, but we'll get back to that later. I like to have a folder under my home directory named sites, where I put any projects I want to serve locally. So let's navigate there and
but we'll get back to that later. I like to have a folder under my home directory named sites, where I put any projects I want to serve locally. So let's navigate there and run valet park. To make sure that it parked correctly, we can run valet parked to see a list of all the sites that have been added because they're in parked folders. Now let's test it out. Remember, we have this folder, which is a stock Laravel app named Floga. Now that we've parked its parent directory, we can visit floga.test, and we should see the site working. There we go. One thing worth noting is that Valet doesn't just serve Laravel apps. It also serves static HTML, WordPress, GraphCMS, and so many other static and PHP-based tools. So if we want, we can just make a new folder, throw an index file in there, and we can see
Linking Single Sites1:44
also serves static HTML, WordPress, GraphCMS, and so many other static and PHP-based tools. So if we want, we can just make a new folder, throw an index file in there, and we can see it running live. But let's say we don't want to park a full directory. Maybe we just have a single site we want to serve. Let's imagine we want to serve a directory that's in the middle of another project directory. We'll head over to the bigproject/bigprojectwebsitedirectory, which houses the website we want to serve. Now from here, we run valelink. And that's it. At this point, we can check out bigproject-website.test. But what if we want to link it with a different name? We can do that too. We run valelink, and then the name we want to serve from, valelink bigproject. Let's get rid of that.
Custom Names and Subdomains2:35
But what if we want to link it with a different name? We can do that too. We run valelink, and then the name we want to serve from, valelink bigproject. Let's get rid of that dash website. Now we can do bigproject.test, and we can also see it there. We can do the same thing to serve any folder at a subdomain. We can imagine a project, for example, with multiple websites hosted at different subdomains. Let's go first to the admin website. We can run valelinkadmin.bigproject, and then we can do the same for the jobs website. And now those two are accessible at subdomains. admin.bigproject.test, and jobs.bigproject.test. Or we can point two subdomains to the same website. Maybe we're testing multi-tenancy in our app. We can link them all. valelink bob.bigproject. valelink sally.bigproject. Multiple subdomains pointing at the same project.
website. Maybe we're testing multi-tenancy in our app. We can link them all. valelink bob.bigproject. valelink sally.bigproject. Multiple subdomains pointing at the same project. You can also use link to change or add to the list of domains and subdomains that resolve to a site in a parked directory. We can go back to our floga directory, which is currently being served at floga.test, because we parked its parent directory. We can also add a subdomain, for example, for our top yoga instructor, Jerry. So let's type valelink jerry.floga. Now, if we type jerry.floga.test, it'll also resolve to the same site. If at any point you want to see a list of all your linked sites, you can run valelinks. You get a nice list of all of them. We haven't covered these features yet, but when you run valelink, you can pass in flags for two other configuration items. If you pass the secure
Link Flags: Secure/Isolate4:40
You get a nice list of all of them. We haven't covered these features yet, but when you run valelink, you can pass in flags for two other configuration items. If you pass the secure flag when you're linking a site, Vali will automatically set this domain or subdomain up as a secured HTTPS site. We'll talk about that more in later videos. And there you see it's secure. If you pass in the isolate flag when you're linking a site, followed by a valid php version, Vali will isolate that site to run on that version of PHP. Again, we'll cover that in another video. So that's it. If we run Vali Park, we're teaching Vali to treat every single subdirectory of our current working directory as an individual site. If we run valelink, we can either have it serve a standalone site, or we can customize the domains and subdomains that are being used to serve our existing parked Vali sites.
site. If we run valelink, we can either have it serve a standalone site, or we can customize the domains and subdomains that are being used to serve our existing parked Vali sites.
