Install extension for macOS built-in PHP

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/php that default php extension directory.

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

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

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

作者: 发表于March 22, 2018 at 2:33 pm

版权信息: 可以任意转载, 转载时请务必以超链接形式标明文章原始出处作者信息及此声明

Tags: ,