Manually upgrading built-in PHP 7.1 to 7.2 with Mac OS X 10.14.5 Mojave and its built-in Apache
First, confirm the path that PHP 7.2 was installed at. In most cases, it should be /usr/local/opt/php@7.2, but there may be some differences. If you're not sure, check your .*shrc file (e.g. .zshrc, .bashrc) — it should have a line like PATH="/usr/local/opt/php@7.2/bin".
Second, copy this path (in my case): /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so. According to what I mentioned in the first step, you might need to adjust this path to fit your situation.
Third, edit your Apache config file:
There might be some differences here, but it should be similar. Find the line:
This is the original PHP 7 module (the 7.1.x one). Comment it out by adding a # at the beginning:
Finally, add a new line pointing to the PHP 7.2 module:
The path should come from the second step.
After all that is done, run sudo apachectl configtest first to make sure everything is OK. Then run sudo apachectl restart — phpinfo() should now display the correct PHP version.
PHP configuration and PHP-FPM
However, this may not fully solve your problem. There are still some things to address: PHP configuration needs to be set, and PHP-FPM should be configured and running.
You can compare the two php.ini files (/etc/php.ini and /usr/local/etc/php/7.2/php.ini) using an editor with a comparison function, to make sure the new one is set to a working state.
Another thing is PHP-FPM. Since the built-in PHP already has PHP-FPM, the newer one should also enable it — otherwise things may not work properly. Modify the Apache config file again by commenting/uncommenting or adding the following lines. Note that php7_module is commented out again — that's the normal practice when using PHP-FPM:
After the modification, remember to restart Apache. Then run the following commands (or just the last one, then restart your Mac) and everything should work as expected: