3

I'm setting up a new macbook (Monterey 12.2.1 chip Apple M1 Pro), and installed PHP 7.4 with homebrew. I configured PHP to run as a module for the Apache2 server that comes with MacOS (Apache/2.4.51). I immediately ran into trouble because gatekeeper wouldn't allow me to run php as an apache module from homebrew until I codesigned it. I did codesign it:

codesign --sign "Mike Andersen" --force --keychain ~/Library/Keychains/login.keychain-db /opt/homebrew/opt/php@7.4/lib/httpd/modules/libphp7.so

And afterwards PHP worked perfectly. Then I installed xdebug with PECL: arch -x86_64 sudo pecl install xdebug

When I checked it from the command line, everything looked right:

php -v
PHP 7.4.28 (cli) (built: Feb 28 2022 07:33:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
    with Xdebug v3.1.3, Copyright (c) 2002-2022, by Derick Rethans

php --ini
Configuration File (php.ini) Path: /opt/homebrew/etc/php/7.4
Loaded Configuration File:         /opt/homebrew/etc/php/7.4/php.ini
Scan for additional .ini files in: /opt/homebrew/etc/php/7.4/conf.d
Additional .ini files parsed:      /opt/homebrew/etc/php/7.4/conf.d/20-ext-opcache.ini,
/opt/homebrew/etc/php/7.4/conf.d/99-xdebug.ini

But loading from a browser failed - the browser listed the 99-xdebug.ini file:

Additional .ini files parsed    /opt/homebrew/etc/php/7.4/conf.d/20-ext-opcache.ini, /opt/homebrew/etc/php/7.4/conf.d/99-xdebug.ini

But nothing else about xdebug. I checked the apache error log and saw:

Failed loading /opt/homebrew/lib/php/pecl/20190902/xdebug.so:  
dlopen(/opt/homebrew/lib/php/pecl/20190902/xdebug.so, 0x0009): 
tried: '/opt/homebrew/lib/php/pecl/20190902/xdebug.so' 
(code signature in <8E9B311F-7332-3812-89A8-91BA8FB71682> '/opt/homebrew/lib/php/pecl/20190902/xdebug.so' 
not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)), 
'/usr/lib/xdebug.so' (no such file)

I tried signing the xdebug.so file as well:

codesign --sign "Mike Andersen" --force --keychain ~/Library/Keychains/login.keychain-db /opt/homebrew/lib/php/pecl/20190902/xdebug.so
/opt/homebrew/lib/php/pecl/20190902/xdebug.so: replacing existing signature

And restarted apache, but still got the same error in the apache log. I've also tried re-signing PHP, no help. I've also tried disabling gatekeeper:

sudo spctl --master-disable

That made no difference either.

I've been googling this all morning, and can't find anything about how to address this problem. Somebody must have seen this by now, so I'm hoping one of you is that somebody and can help a brother out. Thanks in advance for any help you can offer.

1 Answers1

6

It looks like the simplest way to fix this problem is to not use the Apache that Apple ships with Mac OS.

I installed apache with brew: brew install apache2

And updated the httpd.conf file for brew to use port 80, and to point to Exactly. The. Same. Libphp7.so file that I used for Apple's Apache. No re-compiling, no codesign, nothing. Then I stopped and disabled Apple's Apache:

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

And finally, restarted brew's apache: brew services restart httpd

Reloaded my phpinfo file, and all the xdebug goodness was there. First try!

I think the root problem here is that Apple compiles Apache to insist on codesigning, and then makes codesigning opaque and difficult. I'd still love to know if there's a real solution to this problem, but until then, use Brew's Apache and you should be good to go.

If you need help with codesigning PHP, this is the guide I used: https://www.simplified.guide/macos/apache-php-homebrew-codesign

  • I have tried every single solution from 10+ threads about this issue. This is the only one that actually worked, first try. So for anyone with the same issue, settle for this. – Jompis Oct 30 '22 at 19:14