October 202308:0529.8k views

No more Docker for PHP

About

I no longer use Homebrew to manage the dependencies for my local web development! And I definitely don't use Docker.

Transcript

Everything I said

00:00

Y'all, I'm done. I'm done using Homebrew to manage the dependencies on my local machine for web development, and I maintain my untarnished record of having never used Docker. Why don't I use Docker? Because I just don't want to. I'm gonna show you how I manage multiple versions of PHP, multiple versions of MySQL, Postgres, if you want it, I don't want it, Redis, and multiple Node versions across multiple

00:30

projects without using Homebrew, without using Docker. It makes my life so easy. The first thing I'm gonna show you is Laravel Herd. Laravel Herd is a desktop application for macOS machines that handles all of my PHP versioning, my local vanity URLs, web serving, all of that kind of stuff. Even though it's called Laravel Herd, it doesn't just support Laravel.

00:53

Out of the box, it supports Laravel and Symfony and WordPress and just plain static HTML, and a whole lot more. It's completely standalone. It doesn't rely on Homebrew or Docker under the hood. Everything you need comes statically bundled in the actual package. You can download newer or older versions of PHP if you need it.

01:15

It comes with DNSMASQ and Nginx statically bundled as well. So you can assign domains and subdomains on a per-project basis, and you can also set the PHP version on a per-project basis. So if we look at my machine here, and we run PHP and we get the version, you'll see I'm running PHP 8.1.24.

01:37

Now, I can just switch that by saying herd use php @8.2, and it'll switch it to 8.2. Even though Herd is a desktop application, I mostly interact with it through the command line here. So now if I run PHP and get the version, you'll see globally, I'm running PHP 8.2. So Herd manages my global PHP installation.

01:59

If we run which php, you'll see that it is in the Herd application support directory. Now, what if I want to run a specific PHP version for this particular application? I can say herd isolate php @8.1 for this specific application.

02:20

So you can see it updated it for 8.1, and then it restarted Nginx for the aaronfrancis.com site. But if I run php V again, you'll see that that is still 8.2. So if you've isolated your PHP version in a particular project, you would run herd php, and that will proxy it through to the specific PHP version for this project.

02:43

That's how I manage all the PHP versions on my machine across a whole bunch of different projects. It makes it so that I don't accidentally end up in Homebrew Hell, which for some reason, I tend to put myself there quite often. So this, this prevents that. I usually use the same PHP version across most projects, which is usually the most recent version, so should you.

03:03

But some projects are a little bit older, and in production, they'll still be running 8.0 maybe, and so I do isolate those projects so that my local machine matches production so that I don't run into any errors there. Before we move on and talk about databases, I wanna talk about domains for just a second. One of the really nice parts about Herd is that it sets up all of those vanity domains.

03:27

It can optionally do subdomains, and it can secure sites if for some reason you need to run a secure site locally. If you're familiar with Laravel Valet, this is gonna look pretty similar to you. That's because Herd comes with Laravel Valet. It sits on top of Laravel Valet. It builds on what Laravel Valet started with.

03:48

So I'm gonna show you how easy Herd makes this. I haven't set up DNSMASQ, I haven't set up Nginx, I haven't set up anything. But if I run herd open, it just works. It just shows up in the browser as aaronfrancis.com, which is the name of the directory, and then .test, which is the TLD that Herd assigns all of your local projects. And the way that this works is I told Herd, "Hey, anything that shows up in this code directory, I just want you to make it available.

04:17

Just make it available. Th- that's where I keep all of my projects." So if I change into a different directory and I say herd open, it'll open that one up, and Herd is gonna manage serving that project as well. If I want to add a subdomain, or I want it to be different than the name of the directory, I can just say herd link, and we'll just call this app.screencasting.com.

04:43

And now I can say herd open, and now app.screentesting-- screencasting.com.test is available, but also screencasting.com. So if I had two separate projects, one was the application and one was the marketing site, or I was testing multi-tenancy maybe, I could set up as many links as I want, and Herd would serve them all at the appropriate domains and subdomains.

05:07

Moving on from Laravel Herd, as much as I love Laravel Herd, that's enough about Herd. Let's talk about Node and databases. To manage multiple versions of Node on my machine, I use a package called Node Env, which is a fork from a similar package used for Ruby called Rbenv, and so it has a long and battle-tested history.

05:28

But the reason I like Node Env is that it changes my Node version when I change into a new directory. So I can pin a project at a specific Node version, and I don't have to remember to run nvm use or run a use command when I change into that directory. Anytime I change in there, it's just gonna use that Node version.

05:49

I'll show you here in this directory, I am running Node version 20.8, but if we change out to the aaronfrancis.com and run there, you'll see that I'm running Node 18.18. And the way that you can control this is you just have a .node version in the directory route. And so if we come back to screencasting, you'll see that the Node version is pinned to 20.8.0.

06:16

And I didn't have to remember anything. I just changed into the project directory, and it set the Node version for me, which is great, 'cause I love not having to remember things. The final thing- that we've gotta talk about is databases. How do we set up multiple databases, multiple versions of a single database? How do we do all of that in a sane and coherent way using a free application called DB Engine?

06:39

DB Engine is a great tool that I use all the time. In fact, it is the only tool that I use to manage what databases I have on my machine here. You can see that MySQL 8.0.27 is the only one that I have starting on login. That's what I use for most of my projects. But the other day, I needed MySQL 8.0.12 because I was testing out something, and it was just as easy as hitting this button, choosing MySQL, and choosing 8.0.12.

07:07

That's it. That's all it took to spin up a new database. I love that. As, as much as I love databases, I don't wanna manage them. I just wanna play with them. So you can do that for MySQL, Postgres, Redis, anything you need, and I like that it's integrated with my favorite SQL GUI, TablePlus, so I can click here, and boom, I'm ready to go.

07:28

I'm ready to play with the database. There's my setup for staying sane across multiple projects with multiple PHP, Node, database versions, types, all of that stuff. I think it's great. I love it. It makes me very productive. You may think that it's way too simple. That's fine. If you liked it, I would love to hear if you think that I've missed anything or if you would do anything differently.

07:49

If you hated it, I don't know that I ... You, you don't have to leave a comment. You really don't. If you think I'm an idiot, eh, that's fine. I'm okay with that. Let me know what you wanna see next. Until the next time, see ya.

Laravel & PHP

More videos on Laravel & PHP

All videos

Get the next one by email

I’ll send you some more. Not too many.

Join 7,500+ other readers.

Read past issues