Install extension for macOS built-in PHP

Volcano 2018-03-22 14:33

macOS High Sierra 10.13.3 ships with PHP 7.1.7. I’m trying to install an extension for the built-in PHP. I tried the pecl command but no lucky because SIP (System Integrity Protection) protection. I can’t add file under the directory/usr/lib/phpthat default php extension directory.

It’s a little difficult but I installed an extension success by compiling manually


  • Install packages
brew install autoconf pcre
  • Download PHP source files for built-in PHP
xcode-select --install
  • Edit the/etc/php.ini, change theextension_dirto/usr/local/lib/php/extensions. The directory is writable. You should make the directory yourself.
  • Copy all extension files from/usr/lib/php/extensionsto/usr/local/lib/php/extensions
  • Download the extension file and compile it

Compile extension

For example, I compile swoole extension with these steps.

  • Download swoole-2.1.1.tgz from
  • Unzip swoole-2.1.1.tgz
tar xzvf swoole-2.1.1.tgz
cd swoole-2.1.1
  • Compile and copy the extension file to/usr/local/lib/php/extensions

[返回] [原文链接]