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

Valet vs Herd0:00

All right, so let's take a look at the process of installing Valet on your local machine. Historically, when we talk about Valet, we're talking about a command-line tool, and that is primarily what we're going to be talking about during the duration of this course. But recently, Laravel released a tool called Herd that bundles Valet and all its dependencies up into a single installer. It's a bit less flexible than command-line Valet, but it would likely prove to be a bit more stable, and it's certainly easier to install. So if you're using Herd, you can skip this video about installing Valet. And for any future videos when I call Valet on the command-line, just replace that with Herd on the command-line, because Herd is just Valet bundled up under a different name.

Installing Valet Dependencies0:32

And for any future videos when I call Valet on the command-line, just replace that with Herd on the command-line, because Herd is just Valet bundled up under a different name. So let's get back to the process of installing Valet on the command-line. Valet has three primary dependencies, Homebrew, a package manager for Mac, php, and Composer, which is PHP's package manager. Let's walk through how you can install all three on your machine. We'll start with Homebrew since you can use Homebrew to install php. If we open up brew.sh, we'll find the homepage for Homebrew, and right at the top here they've got a bash script that we can copy. Now let's open up our terminal, paste the command, and run it.

got a bash script that we can copy. Now let's open up our terminal, paste the command, and run it. One quick note, Homebrew will be installed in a different location depending on whether you have a M1 or M2 Mac or a traditional Mac. It will be in /usr/local in one of the older Macs, and it will be in /opt/homebrew in one of the newer Macs. Homebrew makes it really easy to install a ton of useful tools. Most of them are meant to be used in the command-line, but you can even use Homebrew to install graphical tools like Chrome or Bear. For now, let's use Homebrew to install PHP.

Installing PHP via Homebrew1:36

tools like Chrome or Bear. For now, let's use Homebrew to install php. The brew command to install a tool is, unsurprisingly, install. With a tool like php, you can either pass it php directly, or you can pass a specific version constraint, like php@8.2. For now, let's just run brew install php. If you watch along with that install, and of course you couldn't have missed mine because I sped it up, you'll notice it downloads dozens of php's dependencies, and then it downloads php, and then it installs those dependencies, and then it installs php. And that's why things with Homebrew, especially the first time around, can take a little bit.

PHP, and then it installs those dependencies, and then it installs php. And that's why things with Homebrew, especially the first time around, can take a little bit of time, is because you're not just downloading a built version of php, you're downloading its entire dependency stack all through Homebrew, which is great, because it sets it all up for you, but that's why something like Hurd might be a little bit faster, because you're just getting the executable file. So at this point, we have a functioning version of php. And as you can see, we can access that php anywhere. If we ask where php is, it lives in /usr/local/bin/php, because that's where all of our Homebrew installations go, /usr/local/bin.

Homebrew Paths and Symlinks2:38

If we ask where php is, it lives in /usr/local/bin/php, because that's where all of our Homebrew installations go, /usr/local/bin. So anything we install with brew install will end up having its executable form at /usr/local/bin. And remember, I'm not recording this on a Silicon Mac, but if you have an M1 or an M2 or any other Silicon devices, that would be /opt/Homebrew instead. So I do want to really quickly show you a little bit about how Homebrew works, because if you're dealing with Valet, if anything goes wrong, understanding where Homebrew's dependencies live will really help you out a lot in debugging. So check out your /usr/local or /opt/Homebrew directories first.

dependencies live will really help you out a lot in debugging. So check out your /user /local or /op /Homebrew directories first. And in there, you're going to see the seller directory, which is where Homebrew installs all of its individual programs. So if we look at seller, here are all the dependencies that we either installed or that were dependencies of something that we installed, you can see PHP right here. So if we go into the PHP directory, we're going to notice that there's just a single install right now 8.2.8. But if we installed multiple versions of PHP, there'd be a folder here for every single one of them.

But if we installed multiple versions of php, there'd be a folder here for every single one of them. And in that folder, oops, you can see that these are all the individual files you need to actually run it, including php right here. But how do we get global access to the specific version? Sim links, that's the magic. So if we take a look at all of the individual entries in the /usr/local/bin directory, we can see that php, for example, is just going to be a sim link to that exact same one we just looked at. So you could have multiple versions of php installed in your machine through Homebrew,

Installing Composer Globally4:11

just looked at. So you could have multiple versions of php installed in your machine through Homebrew, and whichever one is linked is going to be the one that's actually accessible at /usr/local/bin/php, and that'll come up later. So we can now run php from the command line anywhere on a machine. Let's wrap up our dependencies by installing Composer. First, let's open up the Composer homepage, which is at getcomposer.org. Fun fact, every time you refresh this page, it randomly regenerates the color of the Composer. I love this dude. All right, so let's tap download, copy the script here.

I love this dude. All right, so let's tap download, copy the script here. Paste it into our terminal, and run it. Now what this script is doing is grabbing an installer file, checking its hash to make sure it wasn't modified, running the installer, and then deleting it. And at this point, we have a file in our current directory named composer.far. And this is a standalone php file, or php archive file. But we don't want to always have to reference Composer in this particular directory. And who wants to have to type .far every time? Not me.

And who wants to have to type .far every time? Not me. So let's move Composer into a global directory and drop the ending. So to move composer.far into /usr/local/bin/composer. So all we're doing is taking that file right there, renaming it to drop.far, and we're putting it into /usr/local/bin. So just like our Homebrew dependencies, it's accessible across the entire system. And now we can go anywhere we want, and we've got access to Composer. And now we're ready. We've got all of our dependencies installed, and we're finally ready to install Valet itself.

Installing and Testing Valet5:40

And now we're ready. We've got all of our dependencies installed, and we're finally ready to install Valet itself. Let's get started. If we run composer install or composer update, it'll operate in our current working directory, which means it'll apply to the application that we're working on right now. But if we add global to a command writing something like maybe composer global require and then a package, it'll install that package at a central location on a machine so we can access it anywhere. And that's what we do with Valet. So let's go.

And that's what we do with Valet. So let's go. So composer global require laravel/valet, and this will install Valet, which is just a normal composer package, into ~/composer, which is your home directory under the .composer directory, and you're going to have access to it globally from there. There's one step left before we can use Valet. We need to run Valet's own installation process. So from anywhere in the terminal, run valet install. Valet will install its own internal dependencies using homebrew. It will configure them all to work together, and it will publish its own configuration.

Valet will install its own internal dependencies using homebrew. It will configure them all to work together, and it will publish its own configuration folder at ~/\.config/Valet. And remember, that's your home directory ~/.config/Valet. We'll talk a little bit more about what all those dependencies are. But as you can see here, we've installed Nginx. We've set up PHP to be running all the time, and PHP-FPM is the version of PHP that is accessible from a web server versus the one we call from the command line. And we're installing something called dnsmasq, which is helping us serve our TLD or the custom domain name ending .test.

And we're installing something called DNSMasq, which is helping us serve our TLD or the custom domain name ending .test. Now that Valet is installed successfully, we can take a look at that directory we're just talking about, .config/Valet, and we can see all sorts of configuration items here. We've got SSL certificates. We've got specific drivers for different types of websites, log files, and all sorts of other configuration items here. We'll learn about those a little bit more later. It's time for the ultimate test, Valet.

We'll learn about those a little bit more later. It's time for the ultimate test, Valet. There we go. We are running Valet. We're running the latest install, and we can see all the commands that we're going to learn about in later videos. At this point, you've got Valet up and running on your machine, and it's time to get started learning how to use it.

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