There are a few pre-packaged and pre-compiled versions of PHP for macOS. This can help in setting up a standard configuration, but if you need to have a different set of features (such as a secure server, or a different database driver), you may need to build PHP and/or your web server yourself. If you are unfamiliar with building and compiling your own software, it's worth checking whether somebody has already built a packaged version of PHP with the features you need.
An easy way to install PHP on macOS is with the » Homebrew packaging manager.
Install Homebrew by following the instructions on the website.
The following alternative resources also offer easy to install packages and precompiled binaries for PHP on macOS: