YouTubevideo· Mar 21, 2024· 7:17
I've been working on a project that needed some pretty intense queries based on geolocation so where any user is at any given point on a map as well as their location relative to specific end points and also just locations on a map so whether that be other users or landmarks and mongod DB was the perfect choice for that but that also meant me
having to figure out how to set up mongod DB on my local environment specific to Mac OS specific to laravel herd and I ran into a little bit of difficulties and that's why I'm making this video to be able to show you how I set up mongod DB on my Mac OS machine locally using Lille herd now following these examples on the mongod DB docs to install the Community Edition everything works really well so xcode install if
that's not already installed you brew tap this mongod DB Brew do the Brew update that usually takes a good 20 30 minutes and then Brew install mongodb Community 7.0 and this also installs like the mongod DB shell as well now this is where things get in a little trickier when you're trying to run services within Mac OS if you're using
Docker of course this gets a lot easier I don't use Docker I use laravel herd and I wanted to figure out how do I I have heard recognize the specific PHP extension and if you're familiar with PHP extensions I have not other than just one small PHP extension I needed a little bit back but that was not even available on my local machine right now usually if you follow all of these steps
and then you use something like DB engine to start your mongod DB service or you just even use the Brew service start mongod DB then everything should be good to go if you use use PHP Artisan serve everything works fine but I like those fancy development testing URLs within Lille herd so I had to figure out how do I make herd recognize this
extension and herd even has these docs on their website to install a PHP extension uses P pecl Peck I think that's how you PR sayle install and then you would do I think it's just mongod DB and then it shows up this specific extension path to based on your PHP version now here's where I got a little
tricka that worked great if I was using PHP 8.3 which I think it automatically pulls in the peal installation for mongodb based on the most recent PHP version that works great but I most of my projects are in PHP 8.2 some of are even H PHP 8.1 and lville herd is great for be able to switch simply between PHP 8.2 PHP 8.3
PHP 8.1 so how do I make Lille herd figure this out of course if you're following these instructions then this PHP docs for installing the mongod DB PHP driver is going to be perfect for you I did all of that everything worked great again for one specific PHP version now I did a little digging and I couldn't specifically find
the information I needed to use Pele to install a specific version of PHP Within These docs the extension version but this number right here this number right here is actually going to be the version of PHP that you're using and so this looks like PHP probably 8.29 is would be buying guess just on the numbers
themselves and if you're use if you try to use that file in p PHP 8.3 for example or PHP 8.1 it's going to throw an error so how do we fix this the solution I came to was after finding some information on stack Overflow was using Brew to install Pele extensions so this fantastic repo and
I'm going to link it in the comments is in description I should say is Brew tap shur extensions and now you just do mongodb and then you can do a PHP version okay and so it looks like after you install let's say mongodb at 8.2 or at 8.1 or whichever versions of mongodb you needed for a specific PHP version you can see here that I have a whole
bunch of stuff and this is the SL opt slome Brew SL opt folder and then we can see that we have my SQL and then mongodb 8.2 is the one that I installed now you're going to take that path and then in this folder is actually going to be a db. file or document and that is the
document that we need to insert into our php.ini per laravel herds instructions if you go to larl herd and you select the open configuration files what you're going to see is your PHP versions that you have installed through laral herd 8.1 8.2 8.3 each one is going to have an II file
based on the version that you're selecting in LEL herd so if I select PHP 8.2 which is the one I need and I open up this PHP I and I file I see that we have this extension saved here so that way anytime I open up or use the larel herd services and I had to stop and then restart all LEL her services and that seemed to work just fine and after I got that PHP file
saved then everything just worked as I expected I had the local version running I could see it in in mongodb compass for example to to pull that up I was using DB engine to start that mongod DB service The Brew service that I installed and using that Brew PHP extension repo that I Linked In the description then I was able to use use
this Lille mongodb driver to start using mongodb within lville basically you just add it on to a model and then you're good to go so yeah if you're running into any issues installing PHP extensions specifically for different versions within Lille herd let me know if there's an easier way to do it than I did but this is the way that worked best for me I don't necessarily know if there was a way to
do it within the Pele install for specifically for 8.1 or 8.2 or 8.3 version of PHP but using that that PHP extension repo to install those extensions via Homebrew everything worked great for me after that so hopefully this helps you and have a great day