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
Prepare
- Install packages
brew install autoconf pcre
- Download PHP source files for built-in PHP
xcode-select --install
- Edit the
/etc/php.ini
, change theextension_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
- Edit
/usr/bin/php-config
, find line
extension_dir='/usr/local/lib/php/extensions/no-debug-non-zts-20090626'
and replace it with
extension_dir='/usr/local/lib/php/extensions'
Compile extension
For example, I compile swoole extension with these steps.
- Download swoole-2.1.1.tgz from pecl.php.net
- Unzip the file and compile the extension
tar xzvf swoole-2.1.1.tgz
cd swoole-2.1.1
phpize
./configure
make
make install