Search code examples
phpmacosphp-extensionpeclintl

Install PHP 7.0 Internationalization extension (Intl) on XAMPP on Mac


I followed the instructions outlined here:

Install PHP Internationalization extension (Intl) on XAMPP on Mac

Ran sudo pecl install intl selected the correct files from the Cellar

then this error happened:

/private/tmp/pear/temp/intl/intl_error.h:24:10: fatal error: 'ext/standard/php_smart_str.h' file not found

include

     ^ 1 error generated. make: *** [php_intl.lo] Error 1 ERROR: `make' failed

No matter, did some research and found out that PHP 7.0.8 deprecated php.smart_str.h to php.smart_string.h

So given my scant knowledge of C++ I copied smart_string.h to smart_str.h and renamed all the headers from STRING to string.....

re-ran pecl -no luck....more errors......without knowing where the .c files are and remaking php (not really interested in going that far) since anyway I'm using XAMPP so that ended that option.

I have php 5.5 on my mac, deep in the usr/local/bin folder so next step was to get pecl to use those files and generate an intl.so file....

Did that....I have the intl.so file so put it in the 'extensions' folder in XAMPP (for reference: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012)

Ran php and came up with this error:

Warning: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so, 9): Symbol not found: _zval_used_for_init Referenced from: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so Expected in: flat namespace in /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/intl.so in Unknown on line 0

I imagine it has to do with different versions?

In any case I can't get pecl to install intl without a make error in PHP 7.0.8 on XAMPP. There is no documentation on this and you'd think that if you deprecate a header.h file you'd update all extensions?

Install intl.so in PHP 7 seems impossible?


Solution

  • After a lot of research I was finally able to resolve this. Detailed steps here:

    before you begin, check which php path is set. it should be /Applications/XAMPP/xamppfiles/bin/php. If not you can change it by PATH="/Applications/XAMPP/xamppfiles/bin:${PATH}". more detail here

    Overall idea is to build the intl-extension from PHP source code on your own. Before you begin make sure you have installed Xcode. Also, install the latest version of autoconf. this might help:

    brew install autoconf
    

    Next download the version of PHP you use in XAMPP from php.net. I am using 7.1.18. This version worked for me: php-7.1.31, I’m guessing if you follow the steps it might work for 7.0 or 7.2 as well. Do let me know if it does or doesnt, I’ll update this post. Do not use PHP 7.3 for Magento 2.3.0, it is not supported.

    Extract the tar.gz file using (I extracted it inside ~/Downloads/ folder )

    tar -xzvf php-7.1.31.tar.gz
    

    cd into the extracted folder

    cd php-7.1.31
    

    change to subfolder ext/intl

    cd ext/intl/
    

    Run these commands to build the extension

    /Applications/XAMPP/bin/phpize
    ./configure --enable-intl --with-php-config=/Applications/XAMPP/bin/php-config --with-icu-dir=/Applications/XAMPP/xamppfiles/
    make
    sudo make install 
    

    you can now delete all files you downloaded and also the extracted folders.

    Open /Applications/XAMPP/xamppfiles/etc/php.ini , and add extension=intl.so

    Restart your Apache using XAMPP GUI and it should work.