PHP extension on MacOS Sierra

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.

Installing PHP 5.4 on Ubuntu 14.04 (Trusty)

Update repository:

$ sudo apt-get install software-properties-common
$ wget https://www.dotdeb.org/dotdeb.gpg
$ sudo apt-key add dotdeb.gpg
$ sudo echo "deb http://packages.dotdeb.org squeeze-php54 all" > /etc/apt/source.list.d/dotdeb_php54.list
$ sudo add-apt-repository ppa:bitcoin/bitcoin
$ sudo apt-get update
$ apt-cache policy php5
php5:
  Installed: (none)
  Candidate: 5.5.9+dfsg-1ubuntu4.17
  Version table:
     5.5.9+dfsg-1ubuntu4.17 0
        500 http://id.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
     5.5.9+dfsg-1ubuntu4 0
        500 http://id.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
     5.4.45-1~dotdeb+6.1 0
        500 http://packages.dotdeb.org/ squeeze-php54/all amd64 Packages
     5.4.43-1~dotdeb+6.1 0
        500 http://packages.dotdeb.org/ squeeze-php54/all amd64 Packages
     5.4.42-1~dotdeb+6.4 0
        500 http://packages.dotdeb.org/ squeeze-php54/all amd64 Packages
     5.4.41-1~dotdeb+6.1 0
        500 http://packages.dotdeb.org/ squeeze-php54/all amd64 Packages

Harusnya si PHP 5.4 udah nongol tuh 5.4.45-1~dotdeb+6.1.

$ sudo apt-get install php5-common=5.4.45-1~dotdeb+6.1
$ sudo apt-get install php5-fpm=5.4.45-1~dotdeb+6.1
$ sudo apt-get install php5-mysql=5.4.45-1~dotdeb+6.1

Kalo pakce CLI:

$ sudo apt-get install php5-cli=5.4.45-1~dotdeb+6.1
$ php --version
PHP 5.4.45-1~dotdeb+6.1 (cli) (built: Sep  4 2015 23:33:03) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

Sumber:

XHP Template Engine on Laravel 4.2

Languages: Indonesian

Limitations

Since new releases of HHVM and XHP, when we want ot use composistion of XHP component on our view, the view’s file should be started with HHVM’s open tag <?hh and there is no closing at the end of file.

It’s impossible by Blade compiler because by default it won’t prepend the HHVM’s open tag and for every Blade’s syntax like @include, @section, @if, @foreach, etc., will be converted with followed by <?php dan ?>.

At the migration process we should mix both methods on how XHP and Blade works.

Continue reading “XHP Template Engine on Laravel 4.2”