Install PHP intl extension using Homebrew on XAMPP

Recently, when trying to install the PHP intl extension for a Symfony2 based web project using Homebrew to following error message kept showing up:

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory /usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

This post steps explains what is needed to install PHP intl extension using Homebrew on XAMPP.

Reinstall required?

Trying to do a quick re-install did not succeed:

bash-3.2$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

It appears Homebrew is already installed. If your intent is to reinstall you should do the following before running this installer again:

bash-3.2$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

So, basically it’s advised to remove existing files and re-start the installer which resulted in

rm: /usr/local/Cellar/libmemcached/1.0.18/AUTHORS: Permission denied

rm: /usr/local/Cellar/libmemcached/1.0.18/bin/memcapable: Permission denied

rm: /usr/local/Cellar/libmemcached/1.0.18/bin/memcat: Permission denied

… and many more errors

Sudo to the rescue?

Ok, so let’s remove the files using sudo:

bash-3.2$ sudo rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

Password: *****

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

/usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

Well, this is kind of embarrassing 🙂

Since the folder have been successfully removed it might just be the brew cleanup command that causes the problems?

bash-3.2$ sudo brew cleanup

/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

/usr/local/bin/brew: line 23: /usr/local/Library/brew.rb: Undefined error: 0

It’s not 🙂 So, after manually removing these directories again it’s time for another attempt to call the brew installer:

bash-3.2$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

==> This script will install:

/usr/local/bin/brew

/usr/local/Library/…

/usr/local/share/man/man1/brew.1

==> The following directories will be made group writable:

/usr/local/sbin

/usr/local/share/man/man7

Press RETURN to continue or any other key to abort

==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/sbin /usr/local/share/man/man7

==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew

==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew

==> Downloading and installing Homebrew…

remote: Counting objects: 3580, done.

remote: Compressing objects: 100% (3426/3426), done.

remote: Total 3580 (delta 35), reused 1458 (delta 18), pack-reused 0

Receiving objects: 100% (3580/3580), 2.74 MiB | 963.00 KiB/s, done.

Resolving deltas: 100% (35/35), done.

From https://github.com/Homebrew/homebrew

* [new branch]      master     -> origin/master

error: unable to unlink old ‘Library/Homebrew/extend/ENV/shared.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/extend/ENV/std.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/extend/ENV/super.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/hooks/bottles.rb’ (Permission denied)

error: unable to create file Library/Homebrew/language/go.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/language/haskell.rb’ (Permission denied)

error: unable to create file Library/Homebrew/language/java.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/language/python.rb’ (Permission denied)

error: unable to create file Library/Homebrew/utils/fork.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/utils/inreplace.rb’ (Permission denied)

error: unable to unlink old ‘Library/Homebrew/utils/json.rb’ (Permission denied)

error: unable to create file Library/Homebrew/utils/popen.rb (Permission denied)

error: unable to unlink old ‘Library/Homebrew/vendor/okjson.rb’ (Permission denied)

Checking out files: 100% (3584/3584), done.

fatal: Could not reset index file to revision ‘origin/master’.

Failed during: git reset –hard origin/master

Almost! As you can see we also need to manually remove the Library/Homebrew folder and finally it works:

bash-3.2$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

==> This script will install:

/usr/local/bin/brew

/usr/local/Library/…

/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort

==> Downloading and installing Homebrew…

remote: Counting objects: 3580, done.

remote: Compressing objects: 100% (3426/3426), done.

remote: Total 3580 (delta 35), reused 1458 (delta 18), pack-reused 0

Receiving objects: 100% (3580/3580), 2.74 MiB | 502.00 KiB/s, done.

Resolving deltas: 100% (35/35), done.

From https://github.com/Homebrew/homebrew

* [new branch]      master     -> origin/master

HEAD is now at f45116a swiftlint: add 0.1.0 bottle.

==> Installation successful!

==> Next steps

Run `brew help` to get started

bash-3.2$ brew help

Example usage:

  brew [info | home | options ] [FORMULA…]

  brew install FORMULA…

  brew uninstall FORMULA…

  brew search [foo]

  brew list [FORMULA…]

  brew update

  brew upgrade [–all | FORMULA…]

  brew pin/unpin [FORMULA…]

Troubleshooting:

  brew doctor

  brew install -vd FORMULA

  brew [–env | config]

Brewing:

  brew create [URL [–no-fetch]]

  brew edit [FORMULA…]

  open https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md

Further help:

  man brew

  brew home

Pretty easy, right? 😉 Now it’s time to actually install the PHP intl extension.

Install PHP intl extension using Homebrew

To actually install the PHP intl extension we can use Homebrew, thanks to Gigamike for the tip:

bash-3.2$ brew install icu4c

==> Downloading https://homebrew.bintray.com/bottles/icu4c-55.1.yosemite.bottle.tar.gz

######################################################################## 100,0%

==> Pouring icu4c-55.1.yosemite.bottle.tar.gz

==> Caveats

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in

parallel can cause all kinds of trouble.

OS X provides libicucore.dylib (but nothing else).

Generally there are no consequences of this for you. If you build your

own software and it requires this formula, you’ll need to add to your

build variables:

    LDFLAGS:  -L/usr/local/opt/icu4c/lib

    CPPFLAGS: -I/usr/local/opt/icu4c/include

==> Summary

🍺  /usr/local/Cellar/icu4c/55.1: 244 files, 66M

And then finally install intl:

bash-3.2$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install intl

Cannot find autoconf phpize failed

In case you get an error Cannot find autoconf

bash-3.2$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install intl

downloading intl-3.0.0.tgz …

Starting to download intl-3.0.0.tgz (248,200 bytes)

…………………………………………….done: 248,200 bytes

150 source files, building

running: phpize

Configuring for:

PHP Api Version:         20121113

Zend Module Api No:      20121212

Zend Extension Api No:   220121212

Cannot find autoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize’ failed

make sure that autoconf is installed and PHP_AUTOCONF is set correctly (which is not set by default when using XAMPP).

You can easily install autoconf through Homebrew too:

bash-3.2$ brew install autoconf

==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.yosemite.bottle.1.tar.gz

######################################################################## 100,0%

==> Pouring autoconf-2.69.yosemite.bottle.1.tar.gz

Warning: This keg was marked linked already, continuing anyway

🍺  /usr/local/Cellar/autoconf/2.69: 70 files, 3,1M

Next, make sure that PHP_AUTOCONF is in your path by checking the path to autoconf:

bash-3.2$ which autoconf

/usr/local/bin/autoconf

 Now set PHP_AUTOCONF:

bash-3.2$ export PHP_AUTOCONF=/usr/local/bin/autoconf

and start the intl installation through PECL again:

bash-3.2$ sudo /Applications/XAMPP/xamppfiles/bin/pecl install intl

downloading intl-3.0.0.tgz …

Starting to download intl-3.0.0.tgz (248,200 bytes)

…………………………………………….done: 248,200 bytes

150 source files, building

running: phpize

Configuring for:

PHP Api Version:         20121113

Zend Module Api No:      20121212

Zend Extension Api No:   220121212

Specify where ICU libraries and headers can be found [DEFAULT] :

building in /private/tmp/pear/temp/pear-build-rootlnRgnx/intl-3.0.0

running: /private/tmp/pear/temp/intl/configure –with-icu-dir=DEFAULT

checking for grep that handles long lines and -e… /usr/bin/grep

checking for egrep… /usr/bin/grep -E

checking for a sed that does not truncate output… /usr/bin/sed

checking for cc… cc

checking whether the C compiler works… yes

checking for C compiler default output file name… a.out

checking for suffix of executables…

checking whether we are cross compiling… no

checking for suffix of object files… o

checking whether we are using the GNU C compiler… yes

checking whether cc accepts -g… yes

checking for cc option to accept ISO C89… none needed

checking how to run the C preprocessor… cc -E

checking for icc… no

checking for suncc… no

checking whether cc understands -c and -o together… yes

checking for system library directory… lib

checking if compiler supports -R… no

checking if compiler supports -Wl,-rpath,… yes

checking build system type… x86_64-apple-darwin14.3.0

checking host system type… x86_64-apple-darwin14.3.0

checking target system type… x86_64-apple-darwin14.3.0

checking for PHP prefix… /Applications/XAMPP/xamppfiles

checking for PHP includes… -I/Applications/XAMPP/xamppfiles/include/php -I/Applications/XAMPP/xamppfiles/include/php/main -I/Applications/XAMPP/xamppfiles/include/php/TSRM -I/Applications/XAMPP/xamppfiles/include/php/Zend -I/Applications/XAMPP/xamppfiles/include/php/ext -I/Applications/XAMPP/xamppfiles/include/php/ext/date/lib

checking for PHP extension directory… /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212

checking for PHP installed headers prefix… /Applications/XAMPP/xamppfiles/include/php

checking if debug is enabled… no

checking if zts is enabled… no

… a lot more messages and compile output and finally:

———————————————————————-

Libraries have been installed in:

   /private/tmp/pear/temp/pear-build-rootlnRgnx/intl-3.0.0/modules

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR’

flag during linking and do at least one of the following:

   – add LIBDIR to the `DYLD_LIBRARY_PATH’ environment variable

     during execution

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

———————————————————————-

Build complete.

Don’t forget to run ‘make test’.

running: make INSTALL_ROOT=”/private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0″ install

Installing shared extensions:     /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/

running: find “/private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0” | xargs ls -dils

10839659   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0

10840601   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications

10840602   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP

10840603   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles

10840604   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib

10840605   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php

10840606   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions

10840607   0 drwxr-xr-x  3 root  wheel     102 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212

10840608 856 -rwxr-xr-x  1 root  wheel  434572 19 Mai 14:48 /private/tmp/pear/temp/pear-build-rootlnRgnx/install-intl-3.0.0/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/intl.so

Build process completed successfully

Installing ‘/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20121212/intl.so’

install ok: channel://pecl.php.net/intl-3.0.0

configuration option “php_ini” is not set to php.ini location

You should add “extension=intl.so” to php.ini

Activate intl Extension in php.ini

Finally, make sure to add

extension=intl.so

to your php.ini and restart Apache. If everything is set up correctly you will see the intl information using phpinfo():

PHP intl extension phpinfo

 You are all set to go!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.