Celeb Glow
news | March 13, 2026

How to get localhost using PHP 7.2 on Mojave?

I'm trying to get PHP7.2 working on localhost, but phpinfo() keeps saying 7.1.19 is in place while ~php -v tells me PHP7.2.18 is in place.

I run ~php -v it says:

PHP 7.2.18 (cli) (built: May 2 2019 13:03:01) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.18, Copyright (c) 1999-2018, by Zend Technologies

~echo $PATH

/usr/local/opt/php@7.2/sbin:/usr/local/opt/php@7.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/VMware I installed PHP7.2 via brew in

➜ php@7.2 pwd

/usr/local/opt/php@7.2

I expect te get on localhost PHP 7.2.18 in place.

UPDATE

Followed these instructions from the link mentioned by @mikken (How to use the php that brew installed?)

Edited httpd.conf in folder /etc/apache2

#LoadModule php7_module libexec/apache2/libphp7.so
LoadModule php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so

If I uncomment the first line and comment the second line, I can run phpinfo() from localhost, however it says it's PHP 7.1.19 and php -v says 7.2.18

In case I comment the first line and uncomment the second line, localhost won't start and php -v says 7.2.18

I also followed these steps, but no luck either.

$ brew update php // get the latest homebrew php packages
$ brew install php@7.2
$ brew link php@7.2 // create an alias to this keg-only version; see comments output during installation
$ echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.bash_profile // add the alias to your path; see comments output during installation
$ source ~/.bash_profile // reload .bash_profile to use the new settings immediately
$ sudo apachectl restart

Also tried brew link php71 --force but that didn't help either.

So it seems the webserver doesn't start when I switch lines httpd.conf

Any steps I can take the get 7.2.18 going?

5 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy