title: Apache on Mac M1 Silicon will not load xdebug.so - "code signature not valid for use in process"
body: <p>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:</p>
  <p>codesign --sign &quot;Mike Andersen&quot; --force --keychain ~/Library/Keychains/login.keychain-db /opt/homebrew/opt/php@7.4/lib/httpd/modules/libphp7.so</p>
  <p>And afterwards PHP worked perfectly. Then I installed xdebug with PECL:
  arch -x86_64 sudo pecl install xdebug</p>
  <p>When I checked it from the command line, everything looked right:</p>
  <pre><code>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
  </code></pre>
  <p>But loading from a browser failed - the browser listed the 99-xdebug.ini file:</p>
  <pre><code>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
  </code></pre>
  <p>But nothing else about xdebug. I checked the apache error log and saw:</p>
  <pre><code>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 &lt;8E9B311F-7332-3812-89A8-91BA8FB71682&gt; '/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)
  </code></pre>
  <p>I tried signing the xdebug.so file as well:</p>
  <pre><code>codesign --sign &quot;Mike Andersen&quot; --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
  </code></pre>
  <p>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:</p>
  <pre><code>sudo spctl --master-disable
  </code></pre>
  <p>That made no difference either.</p>
  <p>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.</p>