【问题标题】:Can't install php Intl extension on MacosX无法在 MacosX 上安装 php Intl 扩展
【发布时间】:2018-06-16 13:57:27
【问题描述】:

我正在关注这个link 来安装这个 PHP 扩展,但我被困在了中间。
当我尝试运行此命令 pecl install intl 时,我收到以下消息:

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

而且我不知道 ICU 图书馆在哪里。
如果我按 Enter 键,我会收到此错误:

configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
ERROR: `/private/tmp/pear/install/intl/configure --with-php-config=/usr/bin/php-config --with-icu-dir=DEFAULT' failed

如何找到 ICU 库的正确路径? 我正在使用带有 PHP 7.1 版的 High Sierra 和 MAMP

【问题讨论】:

  • 它可能使用brew 工作,如该问题的答案所述:*.com/questions/42085083/…
  • 我已经尝试过了,但还是不行,你看我正在尝试为 symfony 安装 PayumBundle 并且它需要这个扩展

标签: php terminal macos-high-sierra intl


【解决方案1】:

ICU 代表 ICU - Unicode 的国际组件

用 brew 安装它

brew update
brew search icu # returns 'icu4c'
brew install icu4c

用 pecl 安装它

sudo pecl update-channels
sudo pecl install intl

installing intl package on osx

【讨论】:

  • 感谢您的回复,但每当我尝试使用sudo pecl install intl时,它仍然要求我输入icu路径
  • 第一种方法,用 brew 怎么样?
  • 是的,我从您提供的链接中找到了路径,非常感谢 :)
  • sudo pecl install intl .command 返回configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works. ERROR: "/private/tmp/pear/install/intl/configure --with-php-config=/usr/local/bin/php-config --with-icu-dir=DEFAULT' failed"
  • sudo pecl install intl for php 7.3 返回错误:In file included from /private/tmp/pear/temp/intl/php_intl.h:34: /private/tmp/pear/temp/intl/intl_error.h:24:10: fatal error: 'ext/standard/php_smart_str.h' file not found #include <ext/standard/php_smart_str.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. make: *** [php_intl.lo] Error 1 ERROR: make' failed`
【解决方案2】:

编辑:在 php@5.6 中仔细查看后,它似乎已经用 'intl' 编译了

php -i | grep intl
... '--enable-intl' ...

所以我的答案通常对 php@5.6 没用(但我猜在某些情况下可能有用)


我今天在尝试从 php56 切换到 php@5.6 时遇到同样的问题。

经过大量挖掘,这是解决方法。

确保干净安装 php@5.6 并使用当前版本

php -v
PHP 5.6.35 (cli) (built: Mar 31 2018 20:21:31)

还要确保有 icu4c

brew update
brew install icu4c

接下来,我们将手动安装和编译 intl

cd /usr/local/src/
wget https://pecl.php.net/get/intl-3.0.0.tg
tar zxf intl-3.0.0.tgz
cd intl-3.0.0/
phpize --clean
phpize
./configure    

这就是诀窍,编辑 Makefile

vi Makefile

修改CXXFLAGS行如下

CXXFLAGS = -g -O2 -std=c++11

CPPFLAGS 的行如下

CPPFLAGS = -DHAVE_CONFIG_H -DU_USING_ICU_NAMESPACE=1

接下来,保存并编译

make
make install

然后瞧

Installing shared extensions:     /usr/local/Cellar/php@5.6/5.6.35/pecl/20131226/

不要忘记将extension="intl.so" 添加到您的 php.ini 中

vi /usr/local/etc/php/5.6/php.ini

(并重新启动 apache)

来源:

【讨论】:

    【解决方案3】:

    从 php.net 下载您在 XAMPP 中使用的 PHP 版本。我正在使用 7.3。这个版本对我有用:php-7.3, 我猜如果您按照步骤操作,它也可能适用于 7.0 或 7.2。

    使用解压 tar.gz 文件(我将它解压到 ~/Downloads/ 文件夹中)

    tar -xzvf php-7.1.31.tar.gz cd 进入解压的文件夹

    cd php-7.1.31 切换到子文件夹 ext/intl

    cd ext/intl/ 运行这些命令来构建扩展

    /Applications/XAMPP/bin/phpize

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

    制作

    sudo 安装

    您现在可以删除所有下载的文件以及提取的文件夹。

    打开 /Applications/XAMPP/xamppfiles/etc/php.ini ,添加 extension=intl.so

    就是这样!使用 XAMPP GUI 重新启动 Apache,它应该可以工作。每次安装新版本的 XAMPP 时都必须运行这些命令。

    【讨论】:

    • 太棒了,你拯救了我的一天!非常感谢您,先生
    • 快速说明,需要先安装autoconf(brew install autoconf)
    • 非常感谢!这对我来说适用于 XAMPP 和 PHP 7.3