MacOS High Sierra comes with PHP. In this article the php --version output:
PHP 7.1.16 (cli) (built: Mar 31 2018 02:59:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.1.16, Copyright (c) 1999-2018, by Zend Technologies
To enable PHP accelerator OPcache add the following on /private/etc/php.ini:
[opcache] zend_extension = opcache.so opcache.enable=1 opcache.enable_cli=0
The opcache.so is installed on default extension_dir which is on /usr/lib/php/extensions/no-debug-non-zts-2016030.
To see enabled extensions use php -m. Typically if you need another extension which are not available such as intl you will need to compile it first.
PHP Internationalization extension intl
We will need to download the extension source code first which is part of ext on php source code. Download the php source code with exact same version php-7.1.6.tar.bz and after extracting it open the Terminal and do:
cd php-7.1.6/ext/intl phpize --force ./configure make make test sudo make install
And then enable it on php.ini:
extension=intl.so
And then verify again with php -m to see if intl extension are enabled.
Okay, that was the ideal things that make it works. But, since the extension is using 3rd party library and using C++ 11, there are more things to do.
Downloading ICU
The intl extension depend on ICU (International Components for Unicode) libraries and the tool icu-config. The easies way is using homebrew, search the library with brew search icu and found with icu4c. Install using brew install icu4c and follow the steps to export then environment variables manually (PATH, CPPFLAGS, LDFLAGS).
Update Config to use C++ 11 and namespace
The file config.m4 needs to tweaks a little to make the extension compiled successfully with Apple LLVM version 10.0.0 (clang-1000.11.45.5). Enable -std=gnu++11 and add -DU_USING_ICU_NAMESPACE=1.
... if test "$PHP_INTL" != "no"; then CXXFLAGS="-std=gnu++11" PHP_REQUIRE_CXX() PHP_SETUP_ICU(INTL_SHARED_LIBADD) PHP_SUBST(INTL_SHARED_LIBADD) . . . PHP_NEW_EXTENSION(intl, . . . $icu_spoof_src, $ext_shared,,$ICU_INCS -Wno-write-strings -D__STDC_LIMIT_MACROS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DU_USING_ICU_NAMESPACE=1,cxx) . . . fi
Installing
The changes config.m4 will affected after re-run phpize which will generate the configure script.
The icu-config will be used by configure script to detect if the ICU library available. After success fully compile with make, the extension will be on modules/intl.so.
Try to run make test to see if the extension working on current php version and make sure no serious exception such as segmentation fault.
Since the default extension_dir is protected using SIP (System Integrity Protection) the make install will fail even with sudo. So let’s say create another extension_dir on /usr/local/lib with mkdir -p /usr/local/lib/php/extensions/no-debug-non-zts-2016030 and manually copy modules/intl.so on that directory.
And on php.ini enable the extension with full path: extension=/usr/local/lib/php/extensions/no-debug-non-zts-2016030/intl.so. Try to run php -m and restart php-fpm.