مرور عیبیابی Valet0:00
I wish I could tell you that Valet always just works, but unfortunately, that's not the case. Valet has a complex set of dependencies that are managed through Homebrew, and your dependencies and your Homebrew install can sometimes get a little bit wonky. The good news is, we've got a lot of tools and tricks we can use to figure out what to do when you get in that situation. We've done our best with Valet to build in tools that diagnose the issues themselves and provide you with some useful errors. But in the case something's not working and Valet doesn't tell you exactly what's wrong, we also have a few diagnostic tools as well as a set of steps you can take that will cover a large portion of common errors with Valet. Before we look at anything else, let's just hone in on what is making you think your Valet install is broken. If it's worked before,
Initial Sanity Checks0:40
errors with Valet. Before we look at anything else, let's just hone in on what is making you think your Valet install is broken. If it's worked before, and it's not working now, you probably want to move on to the rest of this video, which is about Valet's built-in diagnostic tools and the steps to fix common Valet errors. However, if you're just getting started for the first time, you may think something's broken, but it's not. So let's start there. If you just set up Valet and you think it's not working, here are the first two steps to take. First, ping anything you want, .test. Any .test domain. Do you get 127.0.0.1 back? That means that Valet is configured correctly, at least at the DNS mask level. If you're not, your Valet is not running, or your DNS mask is not set up correctly. This is not the episode where we'll talk a ton about how
at least at the DNSMasq level. If you're not, your Valet is not running, or your DNSMasq is not set up correctly. This is not the episode where we'll talk a ton about how Valet actually works, but since I'm mentioning DNSMasq, I just want to point it out here that it is an open source tool for handling DNS on your local machine. It's what Valet uses to capture all .test domains and point it over to itself. So that's the first good step. Most people, when they have Valet trouble, at least are able to see this work. Second, run valet park and then run valet links. These two commands will give you a list of all of the sites that Valet is capable of serving. If you see your site there and it's not responding, that means we have to go further into our troubleshooting process. But either if the ping didn't work, or you didn't see your site here, you've got to step back a
Built-in Diagnostic Tools1:54
not responding, that means we have to go further into our troubleshooting process. But either if the ping didn't work, or you didn't see your site here, you've got to step back a second and make sure that you've installed Valet correctly, which should make the ping work, and you've actually either parked or linked your directories correctly so that they show up in one of these lists. If the ping worked, and if you saw your site in one of those lists, it's time to dive deeper into diagnosis. So first, let's take a look at Valet's built-in diagnostic tools. There are two that it comes with out of the box, valet status and valet diagnose. valet status is a simple command. It's designed to make sure the main services Valet relies on are running, and that they're running as the right user. When you first run valet status, your output will be a series of questions
sure the main services Valet relies on are running, and that they're running as the right user. When you first run valet status, your output will be a series of questions and their answers. Is Valet fully installed? Is nginx installed? Is nginx running? Is nginx running as root? The answer to all these should be yes, and if any of them are no, that's the first place to look to solve your problem. If something's not running, the solution is usually as simple as running valet restart. That stops all of Valet's services and starts them again. If something's not running as the right user, it's a little bit more complex. That means your Valet install was run incorrectly, which is pretty uncommon, or more likely you or some other dependency installed one of these tools before Valet could get to it. In this circumstance, my best recommendation would be to uninstall that service, for example,
or some other dependency installed one of these tools before Valet could get to it. In this circumstance, my best recommendation would be to uninstall that service, for example, brew uninstall nginx, and then run valet install again so Valet can install it correctly. And again, if you're in this situation, if you would say nginx is installed, nginx is running, but then nginx is not running as root. If Valet isn't fully installed, if it's config isn't valid, or any of the dependencies aren't even installed, the next step would be to run valet install. That's the slowest solution to any of these being no, but it is the strongest possible option. So again, if any of these are no, the first step is to just run valet restart if it's something that's not running. If it's something not running at root, or something not installed or not configured correctly, Valet installs your next best bet.
Common Fix Commands3:42
if it's something that's not running. If it's something not running at root, or something not installed or not configured correctly, Valet installs your next best bet. The second diagnostic command Valet offers is called valet diagnose. This is a much more robust command, and it's meant less for you to use and more for you to paste in when asking issues on GitHub. We'll get to that in just a bit. So let's say Valet status didn't make the problem clear. What do you do next? While it may seem reasonable to go look at the nginx logs or the php logs, which you certainly can do, there are a few commands you can run that fix 98% of Valet errors. So I'd get started with those. First, you want to update homebrew, brew update and brew upgrade. When you run brew update, it will update homebrew to the latest version. And when you run brew upgrade, it will update all your dependencies to the
homebrew, brew update and brew upgrade. When you run brew update, it will update homebrew to the latest version. And when you run brew upgrade, it will update all your dependencies to the latest versions. From there, you can run composer self-update and composer global-update. Similar to brew update, composer self-update makes sure composer is the latest version. composer global-update takes your global composer dependencies, which means it's not for your local directory, but it's the ones you're running globally, like Valet, and updates all of those. Once you've run both of these sets of commands, you've got the latest version of homebrew and all the dependencies you've installed using it, and the latest version of composer and all the dependencies you've installed using that. Finally, I'd run valet restart. This doesn't reinstall Valet or reconfigure anything. It just takes all the services that
and all the dependencies you've installed using that. Finally, I'd run valet restart. This doesn't reinstall Valet or reconfigure anything. It just takes all the services that it manages, stops them, and starts them again so they have the chance to make sure that they're really picking up on any updates you're doing here. Finally, if you don't mind, I would say the next global step you should take is to restart your machine. You'd be amazed to see how many problems with Homebrew and internal macOS dependencies and DNS configuration can be solved by just restarting your machine. If none of those solutions work, there's one more thing you can do before we have to start digging into what the actual problem is, and that's to run valet install again. Valet install does not wipe all of your current configuration items, but it does run through the whole installation process again to make sure that
Checking Logs5:28
that's to run valet install again. valet install does not wipe all of your current configuration items, but it does run through the whole installation process again to make sure that everything is installed and installed where it should be. It'll take a little bit longer than all the rest of these commands, but it can fix a lot of problems. Now, if that doesn't work, it's time to dig a little bit deeper. First, I'd take a look at your logs using valet log, which we covered in a previous episode. By default, you're going to be able to see the nginx log and the phpfpm log. You can see I added mailpit myself in that episode. So take a look at those and see if you see any errors in there that indicate any problems with your php setup or your nginx setup. If that doesn't work, it's probably time to ask for help. If you're asking for help for valet on GitHub, there's two places to go,
Getting Help on GitHub6:02
with your php setup or your nginx setup. If that doesn't work, it's probably time to ask for help. If you're asking for help for valet on GitHub, there's two places to go, issues and discussions. When you hit new issue, it's going to become clear that this is really only for two things, bug reports and security vulnerabilities. And unfortunately, it's not a bug report that you can't figure out how to make it work unless it's actually broken. So what you want to go to instead is discussions, and discussions are a great place for you to go if you get stuck. You can come down to Q&A and ask for help here. One thing worth noting is that we have an issue template that says if you are putting in a bug report, you have to run these commands, which we've already talked about, but you also have to put steps to reproduce and a diagnosis. I would say even if you're just putting a discussion in,
have to run these commands, which we've already talked about, but you also have to put steps to reproduce and a diagnosis. I would say even if you're just putting a discussion in, you should also put in a description of what's going on, steps to reproduce and the diagnosis. So let's take a look at the valet diagnose command really quickly. If you run valet diagnose, you're just going to see a timer running for a while. This is running 40 different diagnostics in the background, and when it's done running all of them, it's going to format them all as HTML for easy pasting into GitHub and copy them to your clipboard. Let's speed this up really quick. All right, so let's try pasting this in and see what we get. So you can see is it's pretty simple HTML using detail and summary, which is really nice because what you get is a title and an expandable accordion for every single one of them.
is it's pretty simple HTML using detail and summary, which is really nice because what you get is a title and an expandable accordion for every single one of them. So for each of these things that we sometimes want you to be able to diagnose that makes it easier for us to come up with solutions to your problems, we now have easy access to all of them. So this is helpful if you're reporting a bug because we might be able to figure out in what environments this bug is going to pop up, but it's also helpful if you are stuck and you need help in the discussions. I want to give credit here that this diagnose command and the vast majority of help that's been given over the years for the more complicated challenges in the valet world have been from a GitHub user and member of the Laravel community named Dr. Byte. This guy right here, if you run into a problem with valet, he's probably going to be
Nuclear Reinstall Option8:06
in the valet world have been from a GitHub user and member of the Laravel community named Dr. Byte. This guy right here, if you run into a problem with valet, he's probably going to be the person who helps you out. So thank you so much to Chris Brown. If none of these solutions that we've talked about so far have worked, there's a very good chance you have a somewhat jumbled homebrew setup. This is most common on older machines when they've migrated the homebrew setup from one version of macOS to another. In this situation, your best nuclear option, and I mean it because it's pretty huge, but it does fix the hairiest of issues, is to uninstall valet, uninstall all of its dependencies, and then reinstall them from scratch. So if you run valet uninstall, you're going to get this big wall of text that's a little bit hard to see here, but at the top of the wall of text that you can't see on mine is that if you don't pass
valet uninstall, you're going to get this big wall of text that's a little bit hard to see here, but at the top of the wall of text that you can't see on mine is that if you don't pass in the --force parameter, it's not actually going to uninstall valet for you. It's just going to give you instructions on how to do it manually. I wouldn't do that. If you're going to uninstall it, I would say valet uninstall --force. Again, all this is doing is giving you instructions and stopping some services. So what I would recommend you doing instead is valet uninstall --force, and then make sure any of valet's dependencies, and that's going to be nginx, php, dnsmasq, ngrok, expose. I think that's it. Make sure that any of these dependencies have uninstalled, and then you can reinstall php, and then use it to install composer, and then use that to install valet, and then valet will install all the rest of your dependencies.
dependencies have uninstalled, and then you can reinstall php, and then use it to install composer, and then use that to install valet, and then valet will install all the rest of your dependencies with the correct configuration. It'll unjumble up your homebrew. With the techniques we covered in this video, you can take even the most misbehaving Laravel valet install and whip it back into shape, and if you're using valet for or later, which you should be because it came out in March of 2023, you're in the most stable valet ever, which has been rewritten in many places for stability and troubleshootability. So I hope you never need this video, but if you did need it, I hope it gave you all the answers you needed.
