Composer error: PHP extension ext-intl * is missing

Updated: January 12, 2024 By: Guest Contributor Post a comment

Introduction

When working with PHP projects, you may occasionally encounter the Composer error message ‘PHP extension ext-intl * is missing’ during package installation or updates, often after modifying your PHP environment or setting up a new project. This message indicates that the intl PHP extension, which is necessary for internationalization features, is not installed or enabled in your current PHP environment. This guide will walk you through the steps to resolve this issue, ensuring a working development setup for your PHP applications.

Understanding the ext-intl Extension

The intl extension is a wrapper for the International Components for Unicode (ICU) library, which provides advanced locale-awareness, formatting, and language-culture manipulation capabilities. It’s a non-default extension that is not enabled out-of-the-box in PHP, although many modern applications and frameworks such as Symfony and Magento 2 require it.

Checking for ext-intl Installation

Before attempting to fix the error, verify if the intl extension is installed:

  1. In a terminal or command prompt, type:
    php -m | grep intl
    If you see ‘intl’ in the output, the extension is installed, and you may only need to enable it.
  2. If there is no output, proceed to the installation instructions.

Enabling or Installing ext-intl on Different Platforms

On Unix/Linux/MacOS

For Unix/Linux distributions:

  1. Open the terminal and install the extension using your package manager, e.g.,
    sudo apt-get install php-intl for Debian/Ubuntu or
    sudo yum install php-intl for CentOS/Fedora.
  2. You may need to specify the PHP version, for instance, php7.4-intl.
  3. After installation, restart your web server:
    sudo service apache2 restart for Apache or
    sudo service nginx restart for Nginx.

For MacOS: Using Homebrew, you can install intl with:

  1. Run brew install [email protected] (or another version if needed), which typically includes intl.
  2. Link the PHP version:brew link --overwrite --force [email protected].
  3. Restart your web server if it’s running.

On Windows

For Windows, the process involves updating the php.ini file:

  1. Locate the php.ini file used by your PHP installation (often in the PHP directory).
  2. Search for the line ;extension=intl or ;extension=php_intl.dll.
  3. Uncomment the line by removing the semicolon (;).
  4. Save the file and restart your web server.

Configuring the Environment

Setting the correct environment paths is also critical:

  1. For Windows, update the system Path environment variable to include the path to the ext directory inside the PHP installation folder.
  2. On Unix-based systems, the extension directory is typically set correctly by default, but you can verify this in php.ini with the extension_dir directive.

Verifying the Installation

  1. Run php -m again to confirm that ‘intl’ appears in the list of modules.
  2. Test the extension is working by running a simple PHP script that uses intl functions, such as Locale::getDisplayLanguage().

Troubleshooting Common Issues

If after following the above steps, you still encounter issues, here are some troubleshooting tips:

  • Check your PHP version – ensure the intl extension installed matches your PHP version.
  • Ensure that only one php.ini file is being used – sometimes different PHP installations can lead to multiple php.ini files.
  • Inspect Apache/Nginx/PHP-FPM logs for additional error information.
  • Verify the ICU library version if you experience specific compatibility issues with the intl extension.

Conclusion

Rectifying the ‘PHP extension ext-intl * is missing’ error in Composer is generally straightforward. By installing or enabling the intl extension and ensuring the correct environment configuration, you can get back to developing with PHP quickly. Remember that different PHP versions and environments might require slightly different steps, but the principles remain the same. With the intl extension properly set up, you’re equipped to handle internationalization in PHP applications with great effectiveness.

Always be sure to consult the official documentation and community support forums if you run into unique challenges. Utilize the resources available within the PHP and Composer communities, as these are constantly updated with the latest troubleshooting tips and tricks.