If you want to use PHP with MySQL, I will always recommend you to install XAMPP to get things done. It’s pretty straightforward and easy to use.
To start, first, go to XAMPP and download the XAMPP for macOS, you’ll generally find download option on the home page itself, if not then go to the download page and select the latest XAMPP version to download, the .dmg file will get downloaded.
Open this .dmg file, you’ll see something like this,
move the XAMPP into your applications folder and open, it will probably look like this,
you’ll see several tabs, open General tab and click on start and wait until Green dot, now go into Services tab, select Apache and MySQL and hit start, wait until green dot.
We can check if it’s working by opening localhost on the browser, we would see this,
now click on phpMyAdmin or open localhost/phpmyadmin we will see our MySQL dashboard.
if your localhost isn’t working,
check on General tab on our XAMPP dashboard and see if there’s a LAN IP on screen, like this,
as we see there’s an IP address, if we open this on browser we would see that PHP is running, just replace localhost with the same mentioned IP it should work, that’s all.