如何在 macOS Mojave 上启用 PHP Intl 扩展?

8
我正在尝试在macOS Mojave上安装Magento(2.3.0)。 Magento显示缺少PHP扩展intl。
我尝试了以下解决方法:
1. 使用cp /etc/php.ini.default php.ini复制php.ini。 2. 在extension=php_intl.dll之前删除“;” 3. 重启Apache sudo apachectl restart。
但以上方法都没有解决问题。
检查php-v时,我看到以下错误:
PHP Warning:  PHP Startup: Unable to load dynamic library 
'/usr/lib/php/extensions/no-debug-non-zts-20160303/php_intl.dll' - 
dlopen(/usr/lib/php/extensions/no-debug-non-zts-20160303/php_intl.dll, 
0x0009): dlopen(): file not found: /usr/lib/php/extensions/no-debug- 
non-zts-20160303/php_intl.dll in Unknown on line 0
PHP 7.1.19 (cli) (built: Aug 17 2018 20:10:18) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

/usr/lib/php/extensions/no-debug-non-zts-20160303目录下只有2个文件,分别是opache.soxdebug.so

如何在我的macOS Mojave上安装或启用“PHP扩展intl”?


extension=php_intl.dll 应该改为 extension=php_intl.so,因为这不是 Windows。 - Martin Zeitler
尝试过了,但是出现了同样的问题 al-OSX:sbin konathal$ php -i | grep intl PHP 警告:PHP 启动时无法加载动态库 '/usr/lib/php/extensions/no-debug-non-zts-20160303/php_intl.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20160303/php_intl.so, 0x0009): dlopen(): file not found: /usr/lib/php/extensions/no-debug-non-zts-20160303/php_intl.so in Unknown on line 0 - Suren Konathala
可能是在OSX High Sierra上安装intl PHP扩展的重复问题。 - Martin Zeitler
3个回答

7
以下是我为您翻译的内容:

这是一个对我有效的解决方案:

  1. 查找所有已安装的 PHP 版本 brew list | grep php
  2. 删除所有版本的 PHP brew remove --ignore-dependencies --force php70 php71 php72(根据上面看到的内容进行选择)
  3. 安装 PHP brew install php72(我选择了 7.2,因为目前有几个供应商还不支持 7.3)
  4. 运行命令 which php 应该会显示已安装 PHP 的路径。复制该路径。
  5. 更新您的 bash_profile vi ~/.bash_profile 并将以下一行添加到文件中: export PATH=/usr/local/php5/bin:$PATH
  6. 保存并运行此命令 source ~/.bash_profile
  7. 使用 php -m | grep intl 检查是否已安装 PHP Intl Extension。如果安装成功,则会看到 intl 列出。否则表示未安装该扩展。

我认为从 PHP 7(不确定版本)开始,扩展默认可用,我们无需在 php.ini 文件中显式启用它们。


1
回答很有帮助,但我认为在“.bash_profile”中添加“export PATH=/usr/local/php5/bin:$PATH”是不必要的吗?我使用“brew”安装了PHP,在我的机器上没有“/usr/local/php5”目录。 - Trott

1
如果您安装了Homebrew的php,将其链接到路径中的一个目录即可解决问题。 brew link --force php@7.3 我遇到了同样的问题,并且通过这种方式解决了它。 这里是我得到详细答案的链接。

-1

从链接中获得帮助并成功编译https://donatstudios.com/Install-PHP-Mcrypt-Extension-in-OS-X

接下来,我们将下载PHP源代码。验证您正在运行的PHP确切版本。可以按以下方式检索版本。 版本已突出显示。

$ php --version
PHP 7.1.19 (cli) (built: Aug 17 2018 18:03:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group

Now we move into a working directory and download the source making sure to update the following for the version from above.


$ cd /tmp
$ curl -L http://php.net/get/php-{{php-version}}.tar.bz2/from/this/mirror > php.tar.bz2
$ open php.tar.bz2

Now we will compile and test the extension.

$ cd php-{{php-version}}/ext/{{extension}}
$ phpize
$ ./configure
$ make
$ make test
$ sudo make install

If all that goes well finally we'll need to add the following to our php.ini - I usually add at it at the end of the file.

extension = {{extension}}
.so
You can verify your installation with the following:

$ php --info | grep {{extension}}\\.

Lastly, depending on your setup now you may want to restart apache.

$ sudo apachectl restart

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