Mac OS X 10.11 El Capitan and later protects system files and processes with a new feature named System Integrity Protection. SIP is a kernel-level feature that limits what the “root” account can do.   It will prevent you from copying the Chilkat PHP shared lib (.so) to the PHP extensions directory.  Also, if you try to move the PHP extension directory elsewhere, you may get an error such as this:

PHP Warning:  PHP Startup: Unable to load dynamic library 'chilkat_9_5_0' 
(tried: /usr/local/lib/php/extensions/chilkat_9_5_0 (dlopen(/usr/local/lib/php/extensions/chilkat_9_5_0, 0x0009): 
dlopen(): file not found: /usr/local/lib/php/extensions/chilkat_9_5_0), 
/usr/local/lib/php/extensions/chilkat_9_5_0.so (dlopen(/usr/local/lib/php/extensions/chilkat_9_5_0.so, 0x0009): 
code signature in (/usr/local/lib/php/extensions/chilkat_9_5_0.so) not valid for use in process: mapped file has no cdhash, completely unsigned? 
Code has to be at least ad-hoc signed.)) in Unknown on line 0

Solution:

You need to codesign the chilkat_9_5_0.so.   Also, if you are trying to copy the chilkat_9_5_0.so to the default PHP extensions directory, you’ll need to temporarily turn off SIP.

How to CodeSign a .so/.dylib on MacOSX

1. First make sure you accept an XCode license.  This is a prerequisite that may not be necessary if you’ve already done it. Open a terminal, and run

sudo xcodebuild -license

Agree to the license..

2. You’ll probably need to know the specific identity names/strings for the command to codesign.  Run this command:

security find-identity -v -p codesigning

The output will be something like this:

  1) 9B8D24EC5FBACDE87E6700C7F03A49734F14DBF1 "Apple Development: username@example.com (4R8P377T9H)"
     1 valid identities found

3) Codesign the chilkat_9_5_0.so. Use the quoted string for one of the identities listed in the previous command.

codesign -f -s "Apple Development: username@example.com (4R8P377T9H)" chilkat_9_5_0.so

How to Temporarily Turn Off System Integrity Protection (SIP) on MacOS

  1. Click the Apple symbol in the Menu bar.
  2. Click Restart…
  3. Hold down Command-R to reboot into Recovery Mode.
  4. Click Utilities.
  5. Select Terminal.
  6. Type csrutil disable.
  7. Press Return or Enter on your keyboard.
  8. Click the Apple symbol in the Menu bar.
  9. Click Restart…

If you later want to start using SIP once again (and you really should), then follow these steps again, except this time you’ll enter csrutil enable in the Terminal instead.

Find the PHP Extensions Directory

The Chilkat PHP extension download provides a showExtDir.php script to show the PHP extensions directory.  Run it to see the directory

php showExtDir.php

Copy the chilkat_9_5_0.php to the PHP Extensions Directory

With SIP temporarily turned off, you may copy the chilkat_9_5_0.so to the PHP extensions directory.

sudo cp chilkat_9_5_0.so /usr/lib/php/extensions/no-debug-non-zts-20180731