After installing PHP on my Mac with brew install php and followed these given instructions on Terminal,
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /opt/homebrew/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
and brew services restart httpd and brew services start php and add index.php to my www directory and chmod 755 it and http://localhost, at the end I got Index of / directory listing instead of index.php PHP code execution result.
Run apachectl -M also showed php_module (shared) on the list.
Did I miss something?