In the following post, I’m going to explain how I fixed the
Unable to load dynamic library intl message error that I got when I tried to run a CakePHP application on my MacBook air m1.
Trying to run cake server on my localhost
When I tried to run the CakePHP server on my localhost using the following command:
$> ./cake server
I got the following error message:
PHP Warning: PHP Startup: Unable to load dynamic library 'intl' (tried: /usr/lib/php/extensions/no-debug-non-zts-20180731/intl (dlopen(/usr/lib/php/extensions/no-debug-non-zts-20180731/intl, 9): image not found), /usr/lib/php/extensions/no-debug-non-zts-20180731/intl.so (dlopen(/usr/lib/php/extensions/no-debug-non-zts-20180731/intl.so, 9): image not found)) in Unknown on line 0 PHP Fatal error: You must enable the intl extension to use CakePHP.
PHP Intl extension
The Internationalization extension (Intl) is a wrapper for the ICU library, a set of C/C++ and Java libraries that provide Unicode and Globalization support for software applications. It enables PHP programmers to perform UCA-conformant collation and date/time/number/currency formatting in their scripts.
I guess that
intl dynamic library has been removed in some MacOS operating system update during the last weeks.
Trying to run PHP
Also when trying to run the following command:
I could read the following message:
PHP Warning: PHP Startup: Unable to load dynamic library 'intl' (tried: /usr/lib/php/extensions/no-debug-non-zts-20180731/intl (dlopen(/usr/lib/php/extensions/no-debug-non-zts-20180731/intl, 9): image not found), /usr/lib/php/extensions/no-debug-non-zts-20180731/intl.so (dlopen(/usr/lib/php/extensions/no-debug-non-zts-20180731/intl.so, 9): image not found)) in Unknown on line 0 WARNING: PHP is not recommended PHP is included in macOS for compatibility with legacy software. Future versions of macOS will not include PHP. PHP 7.3.24-(to be removed in future macOS) (cli) (built: Feb 28 2021 09:53:14) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
Apple official notes
I looked for information about this topic and I found the following release notes where they shared the following notes:
Scripting Language Runtimes
Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app.
Apple intends to remove scripting languages runtime in future releases and they advise that is your responsibility to provide PHP to run your apps.
Installing PHP with homebrew
The first solution to the problem that we face is to install PHP using
homebrew. Using the following command in the command line we can install version 7.4 of PHP.
$> brew install firstname.lastname@example.org
The following command creates symlinks to the previous installation we performed manually in Cellar. This allows us to have the flexibility to install things on our own but still have these participate as dependencies in homebrew formulas.
$> brew link email@example.com --force
After installing it if we run the command to see the version of PHP that we have available in our
$> php -v
We see that the previous error doesn’t show anymore:
PHP 7.4.27 (cli) (built: Dec 16 2021 18:14:21) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.27, Copyright (c), by Zend Technologies
Using Docker to run your CakePHP app
Then we can run the following commands to build the container image:
docker build -t my-app .
and run it:
docker run -p 8080:80 -d my-app
In this case, we will be able to run a PHP app without installing it locally.
Hope the post was helpful and that you can run your PHP applications on your MacBook air.