Introducing Valet Dependencies0:00
When you're serving your sites with Valet, you're almost always going to work with some dependencies that Valet does not provide for you out of the box, things like databases and cache and queues and mailers and things like that. But the good news is that your Valet sites play very nicely with other dependency managers that you can install on your Mac, and they will give you access to those sorts of tools and many more. So let's take a look. First, I want to give you my recommendation. The easiest way to set up just these three dependencies, which is MySQL, Redis, and Postgres, is through a free little app created by the folks at TablePlus called dbEngine.
Installing dbEngine Services0:28
The easiest way to set up just these three dependencies, which is MySQL, Redis, and Postgres, is through a free little app created by the folks at TablePlus called dbEngine. I don't know if that's how you're supposed to pronounce it, but that's how I say it. You can download the app on macOS, and it makes it super easy to install Postgres, MySQL, and Redis with almost no work at all on your part. So you head over to dbengine.com, and you just hit Download for Mac. We drag here to install it, and now let's go open it up. All right, so this is what dbEngine looks like out of the box. As you can see, it's showing all the services that we have running through Homebrew, which is a nice and easy way to see if they're running and also to manage them, but that's not what
As you can see, it's showing all the services that we have running through Homebrew, which is a nice and easy way to see if they're running and also to manage them, but that's not what we're here for right now. So let's close that down. What we want to do is make sure that dbEngine is running all the time, so we launch it login, and we want to spin up our first server. So let's spin up a MySQL server, and you can see we can pick different options here, but we're going to pick the latest. And you can name it to differentiate between different servers, and we're going to have a MySQL 8 server, and maybe we'll have another one later.
And you can name it to differentiate between different servers, and we're going to have a MySQL 8 server, and maybe we'll have another one later. We're going to use the default port. We can choose the socket we want. We can also choose to use different configuration files if we want to customize how our MySQL install runs. We're going to ignore that for right now because I don't need to, but it's nice to know that you can. We're also going to say that this particular server, not just the dbEngine app, should start on login.
We're also going to say that this particular server, not just the dbEngine app, should start on login. As you can see here, you have the default user of root with no password, which might seem strange to you, but that actually is the default for most local macOS apps, and it's also what Laravel assumes you're going to use by default. When we hit create, we have to hit start, and it's going to download any binaries it needs, and then it's going to start up that server. And there we go. So one thing we want any time we're working with local databases and caches like this is the ability to inspect what's actually going on inside of that database.
Connecting via TablePlus2:15
So one thing we want any time we're working with local databases and caches like this is the ability to inspect what's actually going on inside of that database. I use a tool called TablePlus, and so we're going to pull that up to connect to that database. So we're going to create a new entry, mysql, and we're going to name it mysql8-dbengine. And so as you can see, the defaults are actually set to what it normally would be. So you got 127.0.0.1, which is local, we've got port 3306, we can set our user to root, and let's just see if it works where we actually have to type those in. No, that's it. So we can save that connection, and if we connect to it now, we can see that this is what you come with out of the box, and we can create a new one saying test app or something.
So we can save that connection, and if we connect to it now, we can see that this is what you come with out of the box, and we can create a new one saying test app or something like that. All right, so this test app right here is now up and running on our dbengine mysql8 instance. So just for fun, let's create another server. This one's going to be mysql, but it's going to be 5.7. MySQL 5.7, we're going to put it on port 3307 instead. Automatically start your own login, same username. Let's start that one.
Automatically start your own login, same username. Let's start that one. Notice when I didn't have the binaries installed already, so it's going to download them and install them for us. And now we've got a mysql5.7 server running, but it's on port 3307 instead of port 3306. So if we go back to TablePlus, we can create a new server, and call this one mysql5.7. And you can see we can leave all these the same except we're going to hit 3307 here instead. Test it. It works. We connect to it.
Configuring Laravel Database Ports3:51
It works. We connect to it. And you can notice that that other one we added just a minute ago is not there. So let's create that one here too. test_app. Great. Now we have that database in both places. So I want to show what it looks like for us to connect to both of these through a Laravel app. So I've actually created a little Laravel app that just tells us what version of MySQL
app. So I've actually created a little Laravel app that just tells us what version of MySQL we're connected to. So let's go take a look at that now. So if we open up our .env file in this app that I built, oops, we're going to want to change that database to use our test_app database that we just created. If you can see in the routes/web.php, the only thing we're doing here is basically just saying select the MySQL version and showing on the page, and that's it. The default .env has us connecting to port 3306. So we should see some version of MySQL 8 when we load this page.
The default .env has us connecting to port 3306. So we should see some version of MySQL 8 when we load this page. So this is show MySQL version. So show MySQL version dot test. It says your current version of MySQL is 8.0.33. So we're connecting to that 8 version. However, if we go to port 3307, we should see this change to 5.7. And look at that. So just that easily, we can have different versions of MySQL up and running on our machine. And we can do the same thing for Postgres and Redis and everything else just by changing.
Managing Dependencies with Homebrew4:55
So just that easily, we can have different versions of MySQL up and running on our machine. And we can do the same thing for Postgres and Redis and everything else just by changing the port that we're connecting through. All right. So let's close those down and take a look at our next dependency manager, Homebrew. And we'll stop these and take a look at Homebrew. And we've already talked about Homebrew just a little bit because it is what powers the dependency management for Valet. You can also use Homebrew to install all sorts of dependencies like MySQL and Redis, but it's not quite as ideal for managing dependencies like databases as it is for managing the dependencies.
You can also use Homebrew to install all sorts of dependencies like MySQL and Redis, but it's not quite as ideal for managing dependencies like databases as it is for managing the dependencies we use for Valet. And the reason is because lots of times I've gotten to places where the best troubleshooting step I can take is to wipe my install and reinstall it. And sometimes that can be a little bit of a pain when you've got some important stuff in your databases. So while I'm going to show you how to do it, I would recommend starting with one of the other tools we talked about here. To install dependencies with Homebrew, you type brew install and then the name of the
other tools we talked about here. To install dependencies with Homebrew, you type brew install and then the name of the dependency. So let's try MySQL again. Now this installs the dependency, but it doesn't always actually start it. So one of the things you always want to do just to make sure that not only is it running now, but it stays running ongoing is brew services start MySQL. And that allows the brew service manager to make sure that this is running all the time. So now we should be able to write mysql -u root. As you can see here, they give the instructions on that.
So now we should be able to write mysql -u root. As you can see here, they give the instructions on that. And that just says run MySQL with user root. And there we go. We're up and running in this version. I do want to specifically name that when I was preparing for this video, I spent almost an hour uninstalling and reinstalling Homebrew managed MySQL to work through all sorts of issues that happened because I last had it installed years ago on this machine, and good luck getting it to work when you have an old version that's not fully cleaned up. So while I am showing you how to use it, I would not recommend it.
luck getting it to work when you have an old version that's not fully cleaned up. So while I am showing you how to use it, I would not recommend it. Okay, so if we're using this, now let's take a look at TablePlus and see what it looks like. I'm going to guess that these exact same configuration settings are going to work. And look, they do. So the same settings that we had set up for dp-engine, which is 127.0.0.1, default port, username of root, no password. Those also work to connect to the Homebrew based version of MySQL. And that means if we connect in here and create that same test app database, and we go back
Those also work to connect to the Homebrew based version of MySQL. And that means if we connect in here and create that same test app database, and we go back to our app and we change it to 3306, we should be able to go to show MySQL version .test. Yep. And there we go. We're connected now to the Homebrew based version of MySQL. So let's stop that. Let's go to services, stop MySQL, and brew uninstall MySQL. Finally we have our last dependency manager, which is the most powerful, but also the most complicated and that is Docker.
Using Docker with Takeout7:37
Finally we have our last dependency manager, which is the most powerful, but also the most complicated and that is Docker. Now with Docker, you have all sorts of different options. You can set up your own Docker Compose files. You can use some prebuilt tools that use Docker. But if you're using Valet, I want to recommend something and I got to say I'm biased because I co-created it with Jose Soto, but it is called Takeout. And the whole point of Takeout is giving you Docker services that are meant to be used not by other Docker services, but by your Valet sites. So you go to takeout.titan.co, you can see that it's a Docker based development only.
not by other Docker services, but by your Valet sites. So you go to takeout.titan.co, you can see that it's a Docker based development only dependency manager. So this is not for production. This is not for creating fully Docker sites. This is just for if you're using a tool like Valet, pulling up Docker dependencies to use on your non-Docker sites. Now just like Homebrew, you can run commands like takeout enable MySQL or takeout enable Elasticsearch or takeout enable Postgres. But unlike Homebrew, you're not running those on your local machine.
Elasticsearch or takeout enable Postgres. But unlike Homebrew, you're not running those on your local machine. You're not dealing with all your local dependencies. These are all spinning up individual Docker containers that contain only that dependency. So if you're having trouble with your MySQL dependency and you want to install it and you delete the container, your personal computer is now not in a bad situation where you have to worry about the configuration, just like I showed with my own computer with MySQL. Instead, that container contained MySQL, now the container is gone and you can start again from scratch. So let's get it installed.
from scratch. So let's get it installed. Installs with Composer. So we just grab this little composer global require, and we go to our computer and we require takeout. Now takeout itself is just a PHP file, but that PHP file runs commands to interact with Docker. So you do already have to have Docker installed in your machine. If you don't, just click on this little link for Docker for Mac, and it'll install it for you quickly.
If you don't, just click on this little link for Docker for Mac, and it'll install it for you quickly. So to start, you can say takeout list, and it'll show you all the containers you're running. And of course, you don't have any right now. So let's look at takeout enable. takeout enable takes you to a list of all the possible services, which unfortunately does not fit in the tiny little screen that I have available for recording. But you can see there's all sorts of dependencies you can do, like storage services that mimic S3, WebSocket servers, Elasticsearch and MailySearch, and much more. For now, because again, this tool doesn't work on little mini screens like this, let's
S3, WebSocket servers, Elasticsearch and MailySearch, and much more. For now, because again, this tool doesn't work on little mini screens like this, let's just run it ourselves. Take out mysql. So you can set up these same questions that we're setting up on dp-engine. We want to use 3306 on this one, but later we could choose to have another version of MySQL running in a different container at 3307 or something else. Which version would you like to use? You can pick the specific version you want. Right now we're just going to go for the latest.
You can pick the specific version you want. Right now we're just going to go for the latest. You can name the volume, and that means that if you want to use the same storage for multiple different containers, you can, or you could name this one MySQL data 8, so you make sure that your 571 has a different volume. You can set your root password, which will allow it to be null by just hitting enter. It's going to download that Docker image, and it's going to tell Docker, spin up this image with these particular configuration settings, with this name, and make it available to our valet sites. All right, so that service is enabled.
to our valet sites. All right, so that service is enabled. Let's go look at Docker real quick to make sure that it's actually running the way we think. And now you can see we have a container here named to, which is take out MySQL 8, and it also gives you the specific version, so if you have multiple versions running, you'll have to MySQL 8.0.16 or whatever else is the different names, and here you can actually inspect the logs that happen to get it working. You normally are not going to have to do this, but you can know that if you ever need to do anything with this particular server, whether it's stop it or delete it or anything else,
You normally are not going to have to do this, but you can know that if you ever need to do anything with this particular server, whether it's stop it or delete it or anything else, you can do that directly from here. So like we've done with all the other dependencies, let's go take a look at TablePlus and just see. There we go. All those same settings work by default. It's already accessible. It already exposes those ports to valet. We don't have to do anything special to connect into Docker.
It already exposes those ports to valet. We don't have to do anything special to connect into Docker. So we're going to create our test app database, and then we're going to go over to our app, and yep, it's already at 3306. And so let's check it out. Here we have a functioning version. Show MySQL version .test. There we go. 8.0.32. So this is now a valet app connecting to a Docker container that is running MySQL for
8.0.32. So this is now a valet app connecting to a Docker container that is running MySQL for us. And again, the benefit of this is we're not touching our local machine with its dependency, but we also didn't have to go the whole way into building a huge Docker Compose setup and having multiple instances of MySQL, one for each of our independent apps. We got a single MySQL instance that we can use for all our apps, but it is getting all the benefits of running in a Docker container. And there's so many other dependencies we can install with Takeout. And again, I can't show you the whole list right here, unfortunately.
And there's so many other dependencies we can install with Takeout. And again, I can't show you the whole list right here, unfortunately. Right? Yeah, I can't show you. But if we go to the Takeout website, you can probably see a list of all of them somewhere in here. Let's take a look. You can see a list of all the services here that are available. Takeout gives you a few other very useful commands. So you just say Takeout, I'll give you a list of all those commands.
Takeout gives you a few other very useful commands. So you just say Takeout, I'll give you a list of all those commands. So you can enable a service, you can disable a service, you can start a container that you've stopped, or you can stop one. So it's not enabled or disabled, but isn't running anymore. You can list all of your services. So use Takeout list, it'll show you all the services that are running. Once again, on the zoomed in version, it doesn't look great, but you can get all sorts of information you might need. If you're a Docker nut, you can get the container ID, you can get the name, so you can pass.
you might need. If you're a Docker nut, you can get the container ID, you can get the name, so you can pass it to other tools, you can get the ports that it's running on the forwarding, and you can get its status. Between the tools we've talked about here, you should be able to get any dependency you want up and running with your Valet sites. Remember my basic recommendation, dbengine to get started, Takeout if you need a lot more options, and Homebrew if you're brave.
