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 Fusion.app/Contents/Public:/opt/X11/bin

I installed PHP7.2 via brew in

➜ php@7.2 pwd

I expect te get on localhost PHP 7.2.18 in place.


Followed these instructions from the link mentioned by @miken32 (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?


➜  apache2 sudo apachectl -t  

httpd: Syntax error on line 178 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so into server: dlopen(/usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so, 10): no suitable image found. Did find:\n\t/usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so: code signature in (/usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.\n\t/usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so: stat() failed with errno=22

Line 178 says:

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

Have to look into it. Somewhere on SO in a older post the suggestion was done if there are any 'strange' characters that might cause the error. Verified it and the only strange one is '@'. However that is Brew's out of the box installation.

  • Right now it‘s difficult to understand what the current problem is, and why you have tried to solve this specific problem. Most probably it‘s all in your text, but it might help if you could apply some more structure and focus on the key points.
    – nohillside
    May 23, 2019 at 6:07

1 Answer 1


You're trying to use the PHP module from HomeBrew with the Apple-provided Apache web server. That is an unsupported configuration on Mojave.

It doesn't work because macOS tries to validate that your software is correctly signed (i.e. not tampered with) - and it fails this check after you have changed which binaries are going to be loaded in. You can fix this by disabling SIP (System Integrity Protection) - but that is a really bad idea, as this would disable the protection on your other programs as well.

The correct way to proceed is to stop using the built-in Apache web server, and instead use a different web server. The easiest transition is to simple use Apache provided by HomeBrew instead.

You can do that by first installing Apache from HomeBrew:

brew install httpd

Then stop macOS from starting up the Apple-provided Apache on boot:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Make sure that the new php module line you have inserted is now not commented, and the old is - i.e. make it look like this:

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

Then start up the new Apache web server installation:

brew services restart httpd

Depending on your settings you will then be able to connect with your browser to localhost:80 or localhost:8080 to view your site.

  • This one really helped me! I can now start localhost:8080 and see 'It Works!". One thing left, where can I find the httpd.conf to make the necessary changes to f.i. point to /Users/<username>/Sites? I have found several httpd.conf files, but none of these make sens if I make the required adjustments. The one in /usr/local/etc/httpd doesn't seems to take effect. May 23, 2019 at 21:23
  • Usually it is something like /usr/local/etc/apache2/2.4/httpd.conf or /usr/local/etc/httpd/httpd.conf, depending on what exactly you installed. Use the command "brew ls -v httpd" to get the list of files installed, and you'll see it there.
    – jksoegaard
    May 23, 2019 at 21:43
  • @user2037412 As this answer got things working for you, please mark the answer as accepted!
    – jksoegaard
    May 23, 2019 at 21:44
  • Thanks! The command brew ls -v httpd show files put in '/usr/local/Cellar/httpd/2.4.39/.bottle/etc/httpd'. There is a httpd.conf file. Given the folderstructure, does that mean something is wrong in the setup? May 23, 2019 at 21:58
  • edited several httpd.conf files and did after each change a 'brew services restart httpd' but it seems no change is taking any effect :( May 24, 2019 at 5:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .