PHP¶
There are several ways to install and prepare a PHP development environment in your local machine. Back during my first teaching career in Taylor's College (late 2020-2022), the obvious choices were XAMPP and MAMP. However, we now have Herd as my recommendation, alongside something like DBngin if your PHP web application requires use of a database.
Skippable 'Story'
Installing either XAMPP or MAMP posed as a huge problem for my students who were using Apple Silicon Macs at the time; during then, only M1 Macs existed and support isn't as widespread yet. Not having widespread support also meant it was not as feasible to have a virtual machine running either Windows or Mac to get around the issue - the only solution then was Parallels, but it's not something students can justify unless they were to use a pirated copy of that software. Even before then, when I was asked to install XAMPP in my local machine during my time learning web development, I remember not liking it at all.. it was very likely how clunky it looked. Now that some years have passed and the transition from Intel Macs to Apple Silicon Macs are more or less complete, I believe this should not be a big problem anymore. I also currently own an Apple Silicon Mac right now, so I could try if I want to.. but honestly I still don't like the idea of using XAMPP or MAMP, so that's probably not going to happen.
As a way to try to make do with this restriction, and out of curiosity (I still owned an Intel-based Mac so I did not face this problem), I sought to install PHP using Homebrew as part of a process of installing each component in the LAMP stack separately (outdated guide here).. the big issue was that it was very daunting and fallible to mistakes along the way - even I gradually felt that it was no longer worth my time to keep on doing this.
Imagine my surprise when an alternative from the people behind the Laravel (a PHP framework) was made available.. Herd is the best solution I have for myself at the moment, letting me manage PHP versions for any PHP projects I may embark on. As an added bonus, Herd allows for managing Node versions as well, if you're into that sort of thing. It does have database management behind a paywall though, unlike if you went ahead with XAMPP or MAMP. That being said, it's not quite an issue - having something like dbngin is a good solution.. even then, installing pre-requisites to carry out database scripting in MySQL/MariaDB/PostgreSQL/etc. using Homebrew or simply using the provided installer from their website is pretty trivial.
Herd prepares a localhost server environment for working with PHP or Node-based web applications. Going forward, this guide assumes that you are using Laravel Herd for PHP web development. If you have not yet installed Herd yet, you can check out the guide on how to do so here.
PHP Environment Setup¶
Upon installing Herd, it should now run automatically each time you start up your machine (unless you configure it otherwise). Select PHP on the menu at the left-hand side. You can select the PHP version(s) you require.

As of writing this guide, PHP version 8.5 is the latest version. Currently, each minor version release of PHP 8 gets two years of active support and an extra two more years of extended support before being deprecated. You can view the currently supported versions on this page.
First PHP Script¶
Inside the Herd directory, create a project folder.
On my macOS system, I like to keep my Herd projects in my user folder: <username>/Herd.
You can put your project folders in a different location in your machine if you prefer.
For now, let's go with naming the project folder test.
Inside that same project folder, prepare a PHP file named index.php.
Contain this simple PHP script inside the file:
Something interesting about this PHP script
I purposely chose the aforementioned PHP code to test whether PHP is working solely because it's a generic file produced when initializing a LAMP server manually in macOS. The outdated guide I made for my ITS30605 students back in 2021/2022 details the process in detail, which involved having this created as part of it.
Linking A New Site in Herd¶
If you do not have any sites set up in Herd, it should look something like this.

In Herd, click on "Add Site". You should see something like as follows, prompting to either create a New Laravel Project or Link existing project (click on this one). Then, navigate to your project folder and click on "Select Project Folder".

You should see something like as follows (I had a site initialized for phpMyAdmin here too).

In here, you can set which PHP version you'd like to run this with (or Node as well, but chances are if you're just creating a LAMP stack project, Node is not as critical).
Now, if you type in http://test.test into the browser's address bar (https://test.test if you clicked on that lock icon from the Herd Sites list), you should see the following:

Congratulations, you created your first PHP file!