How to Install and Fix PHP intl Extension on macOS with XAMPP

Installing and enabling the PHP intl extension on macOS using XAMPP requires careful attention to environment paths, dependencies, and PHP version compatibility. This guide walks you through the correct and tested process using Homebrew, PECL, and manual configuration.
Step-by-Step Installation Guide
1. Verify You’re Using XAMPP’s PHP in Terminal
By default, macOS may use its system PHP or a Homebrew-installed version. To ensure you’re using XAMPP’s PHP, you need to check which PHP binary your terminal is using.
which php
The expected output should be:
/Applications/XAMPP/xamppfiles/bin/php
If the output shows a different path, you need to update your terminal’s PATH environment variable. Add this line to your shell configuration file, which is either .zshrc
for Zsh or .bash_profile
for Bash:
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
After making this change, reload your shell configuration:
source ~/.zshrc # or source ~/.bash_profile
2. Install ICU4C (Dependency for intl)
The intl extension requires ICU4C (International Components for Unicode) as a dependency. Install it using Homebrew:
brew install icu4c
Important Note: The ICU installation path varies depending on your Mac’s architecture:
- Intel-based Macs:
/usr/local/opt/icu4c
- Apple Silicon Macs:
/opt/homebrew/opt/icu4c
3. Install intl Extension via PECL
PECL (PHP Extension Community Library) is the recommended way to install PHP extensions. First, update the PECL channels and then install the intl extension:
sudo pecl update-channels
sudo pecl install intl
Note: If the installation process prompts you for the ICU path, provide the appropriate path based on your system architecture as mentioned in step 2.
Important Considerations:
PECL may sometimes compile the extension against the wrong PHP binary, such as a Homebrew-installed PHP instead of XAMPP’s PHP. If PECL fails or links against the wrong version, you can use the manual installation method described later in this guide.
4. Enable the Extension in php.ini
After successfully installing the intl extension, you need to enable it in PHP’s configuration file. Open XAMPP’s php.ini file:
nano /Applications/XAMPP/xamppfiles/etc/php.ini
Look for the following line in the file:
;extension=intl.so
Remove the semicolon at the beginning to uncomment and enable the extension:
extension=intl.so
Note: The .so
extension is used for macOS and Linux systems. Windows systems use .dll
files instead.
You should also verify that the extension_dir
directive is correctly set. It should look something like this:
extension_dir="/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-[version]/"
Replace [version]
with the actual PHP API version number that matches your installation.
5. Restart Apache
To apply the configuration changes, you need to restart Apache. You can do this through the XAMPP control panel, or use the command line:
sudo /Applications/XAMPP/xamppfiles/bin/apachectl restart
6. Verify Installation
To confirm that the intl extension is properly installed and loaded, run the following command:
php -m | grep intl
If the installation was successful, this command will output:
intl
Common Issues & Troubleshooting
Issue: intl.so Not Found or Not Loaded
This problem typically occurs when the intl.so file doesn’t exist in the directory specified by the extension_dir
directive in php.ini. First, verify that the intl.so file exists in the correct location. If the file is missing, PECL may have installed it in Homebrew’s PHP extensions directory instead of XAMPP’s directory. While you could manually copy the file to XAMPP’s extensions directory, this approach is not recommended for long-term use due to potential compatibility issues.
Issue: Wrong PHP Version Used
This issue arises when the system uses the wrong phpize and php-config binaries during the extension compilation process. To verify which versions are being used, run:
which phpize
which php-config
If these commands point to Homebrew’s PHP installation instead of XAMPP’s, you need to adjust your PATH environment variable again:
export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
Manual Installation (Alternative if PECL Fails)
If PECL doesn’t work properly with your XAMPP installation, you can compile the intl extension manually. This process gives you more control over the compilation process:
cd /tmp
pecl download intl
tar -xzf intl-*.tgz
cd intl-*
phpize
./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config --with-icu-dir=/opt/homebrew/opt/icu4c
make
sudo make install
After the manual compilation completes successfully, enable the extension in php.ini as described in step 4.
Summary Table
Step | Command/Action | Notes |
---|---|---|
Verify PHP path | which php | Ensure you’re using XAMPP’s PHP |
Update PATH | export PATH=... | Required for correct phpize/pecl usage |
Install ICU4C | brew install icu4c | Required for intl |
Install intl | sudo pecl install intl | Use correct ICU path if prompted |
Manual build (optional) | phpize , ./configure , make , make install | Use if PECL fails |
Enable in php.ini | extension=intl.so | Remove semicolon and set extension_dir properly |
Restart Apache | Apache control panel or CLI restart | Reload configuration |
Verify installation | `php -m | grep intl` |
Conclusion
Successfully completing this process to install PHP intl extension macOS XAMPP ensures that your development environment has access to powerful internationalization functions for building multilingual applications. The intl extension is essential for modern PHP development, particularly when working with Unicode text processing, locale-specific formatting, and international character handling. By following this comprehensive guide, you’ve not only resolved the immediate need to install PHP intl extension macOS XAMPP, but also gained valuable knowledge about PHP extension management, dependency resolution, and troubleshooting techniques that will serve you well in future development scenarios. Remember to verify your installation periodically after XAMPP updates, as system changes may occasionally require you to reinstall or reconfigure the intl extension to maintain optimal functionality
Leave a Reply