Mac OS: Intl extension is not loaded

送分小仙女□ 提交于 2019-11-30 09:47:57

Brew's PHP 7.1, 7.2 and 7.3 all have INTL enabled by default.


Most probably, you're just using your Mac OS' bundles version of PHP.

Run

ls -l $(which php)

to find out where the current PHP binary is located and whether it is symlinked to a Brew installation or not. In my case, for example:

lrwxr-xr-x 1 27 May 23 16:30 /usr/local/bin/php -> ../Cellar/php/7.3.5/bin/php

Meaning that my php is linked to Brew's 7.3.5 version.

If you are NOT using Brew's PHP, you'll see something like

-rwxr-xr-x 1 11169664 Mar 21 07:09 /usr/bin/php

Installing PHP through Brew

Find out whether you've already installed PHP:

brew list | grep php

If there is any output, and your version of PHP is present, go to step 2, or use step 1 to update PHP to the latest version.

1. Install Homebrew's PHP

brew install php@7.3

(or 7.2, 7.1). If Brew complains about not being able to find a formula, you might have messed with taps. Instead of php@7.3, you could try to supply the full path to the current php formula:

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/php.rb

Still not working, check whether you are running a recent version of Homebrew brew --version.

Homebrew 2.1.3-31-geaf2370
Homebrew/homebrew-core (git revision fd1ef; last commit 2019-05-25)
Homebrew/homebrew-cask (git revision 16d50; last commit 2019-05-26)

2. Link Homebrew's PHP

Now, to have php 'in your path', there are two options.

a) Either homebrew's version must be linked from its install location (/usr/local/bin/Cellar/php....) to a directory in your path (e.g., /usr/local/bin). To do this, run:

brew link --force php@7.3

If you are not able to link, this is typically caused by set permissions or System Integrity Protection. In the first case, try sudo chown "$USER":admin /usr/local/bin/php.

b) Or, add the /usr/local/opt/php@7.3 directory (opt-prefix) to your $PATH variable. E.g., for Bash:

echo 'export PATH="/usr/local/opt/php@7.3/bin:/usr/local/opt/php@7.3/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

3. Validate installation

ls -l $(which php)

should show that php is linked to a Homebrew PHP installation in /usr/local/bin/Cellar.

php -v

should show the recently installed version of PHP. Try to restart your terminal if that's not the case.

php -i | grep -i intl

should show some information about the current install of intl.

If you're using webservers and/or PHP FPM, this is the time to restart those services. (Or restart your system, if you don't know how to do that and cannot figure out).

Possible issues

If you still get warnings about missing extensions (Unable to load dynamic library, etc.), then your php.ini is messed up.

Find the current location of php's ini

$ php -i | grep \.ini

Configuration File (php.ini) Path => /usr/local/etc/php/7.3
Loaded Configuration File => /usr/local/etc/php/7.3/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed => /usr/local/etc/php/7.3/conf.d/ext-opcache.ini
....

Edit /usr/local/etc/php/7.3/php.ini and find the offending extension load (e.g., extension="myext.so"). Comment out those that cannot be found.

Homebrew permissions

Some argue that it's a good idea to chown /usr/local.

sudo chown -R "$USER":admin /usr/local

This will make installing things here, by hand and through Homebrew, a lot easier, but also a bit less secure too, since non-root processes are now allowed to write here too.

Your web-application is using a different version of PHP.

Make sure that it doesn't... The configuration of this depends on the used webserver. A first step would be to output the current PHP configuration in your web-application with <?php phpinfo();.

This explains steps for Apache.

Another way to get a webserver + PHP stack running quicly is using Laravel Valet.

Installing additional extensions

To install additional PHP extensions, use PEAR.

pear -V should output the current PEAR and PHP version.

PEAR Version: 1.10.9
PHP Version: 7.3.5
Zend Engine Version: 3.3.5

Now, to install an extension, for example, PHP's yaml extension:

pear install yaml

There might be an issue with brew

You could try to use this as mentioned there:

brew tap kyslik/homebrew-php

brew install kyslik/php/php71-intl

i tried all but intl not working in mac so please uninstall xampp and install mamp it will work

Since php 7 it's not necessary load the extension php_intl.so, what do you need to do?, edit your php.ini and delete or comment the line that is loading the extension php_intl.so, after this reload your apache and try again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!