MacOS Catalina, how to change Apache PHP version

In this post we see how to change the PHP version of Apache in MacOS Catalina.

MacOS Catalina comes with Apache and PHP 7.3 already preinstalled.
Sometimes we may need to run a different version of PHP with Apache.
For example Magento 2 needs PHP 7.2 to run .

Install PHP 7.2 using Homebrew

To checkout the current PHP version, run:

php -v

In my case, it was PHP 7.3.

So, first we need to install the PHP version we need. I used Homebrew to install PHP 7.2.

<!-- wp:syntaxhighlighter/code {"language":"bash"} -->
<pre class="wp-block-syntaxhighlighter-code">php -v</pre>
<!-- /wp:syntaxhighlighter/code -->