First install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install stable version of php using Homebrew
brew install php
This will start updating Homebrew – Updating tap and Formulae.
The following dependencies will normally be installed through the command above. If your differs, the dependencies will install when it is necessary.
apr, apr-util, argon2, aspell, m4, autoconf, brotli, gettext, libunistring, libidn2, libmetalink, libssh2, c-ares, jemalloc, libev, nghttp2, openldap, rtmpdump, zstd, curl, libtool, unixodbc, freetds, libpng, freetype, fontconfig, jpeg, libtiff, webp, gd, libffi, glib, gmp, icu4c, krb5, libpq, libsodium, libzip, oniguruma, pcre2 and tidy-html5
After all dependencies installation
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/8.0/
To have launchd start php now and restart at login:
brew services start php
Or, if you don’t want/need a background service you can just run:
php-fpm