在MacosX上无法安装PHP Intl扩展

14

我正在按照链接安装PHP扩展,但是我卡在了中间。
当我尝试运行这个命令pecl install intl时,我得到了下面的信息:

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

我不知道 ICU 库的位置。
如果我按回车键,就会出现这个错误:

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库的正确路径? 我正在使用High Sierra和带有PHP版本7.1的MAMP。


可能可以使用brew,就像在这个问题的答案中描述的那样:https://dev59.com/Ap7ha4cB1Zd3GeqPqemC - Kilian Batzner
我已经尝试过了,但仍然无法工作。你看,我正在尝试为Symfony安装PayumBundle,它需要这个扩展。 - SlimenTN
3个回答

8
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


1
谢谢您的回复,但每当我尝试使用“sudo pecl install intl”时,它仍然要求我输入icu路径。 - SlimenTN
https://stackoverflow.com/questions/13726386/how-to-point-configure-down-the-right-path-to-icu - Cedric
1
是的,我从您提供的链接中找到了路径,非常感谢 :) - SlimenTN
3
请执行以下命令:sudo pecl install intl。 如果出现错误信息 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",请确认您的 ICU 安装前缀并确保 icu-config 可用。 - mapmalith
4
在安装 php 7.3intl 扩展时出现错误。执行命令 sudo pecl install intl 后返回以下错误信息:在文件 /private/tmp/pear/temp/intl/php_intl.h 中包含: /private/tmp/pear/temp/intl/intl_error.h:24:10: 致命错误:无法找到 'ext/standard/php_smart_str.h' 文件 #include ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. make: *** [php_intl.lo] Error 1 ERROR: `make' failed` - Shankar
显示剩余5条评论

5

编辑:在更好地查看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/

不要忘记在你的php.ini中添加extension="intl.so"

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

(并重新启动apache)

来源:


4

从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 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/

make

sudo make install

现在可以删除所有已下载和已解压缩的文件夹。

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

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


太棒了,你救了我的一天!非常感谢您,先生。 - Andresa Martins
一个快速的提示,您需要先安装autoconf(brew install autoconf)。 - Andresa Martins
非常感谢!这对我来说很有效,使用的是XAMPP和PHP 7.3。 - Marvin Krüger

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接