About problem in installing ext-sodium * for installing lcobucci/jwt 4.3.0 and kreait/firebase-tokens 4.3.0 for laravel project

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Solving Dependency Hell: Installing ext-sodium for JWT and Firebase Token Packages in Laravel

As senior developers building robust applications, we often encounter dependency hell—situations where seemingly simple package installations lead to complex system-level errors. This is particularly true when dealing with PHP extensions, which are the foundational tools many modern libraries rely on.

Recently, I encountered a specific roadblock while setting up a Laravel project that utilized packages like lcobucci/jwt and kreait/firebase-tokens. The installation process failed because these packages depend on the PHP Sodium extension (ext-sodium), which was missing or improperly configured on my system.

This post will walk you through the exact problem, analyze why standard compilation methods fail, and provide the correct, practical solutions for enabling essential extensions in your PHP environment.

Understanding the Core Conflict

The error message clearly outlines the dependency chain:

Problem 1
- lcobucci/jwt is locked to version 4.3.0 and an update of this package was not requested.
- lcobucci/jwt 4.3.0 requires ext-sodium * -> it is missing from your system. Install or enable PHP's sodium extension.

The conflict arises because Composer resolves the dependencies, finds that lcobucci/jwt needs the Sodium functionality, and demands the extension be present. When we attempt to install the underlying C extension (libsodium) using PECL (PHP Extension Community Library), we run into system-level hurdles related to PHP version compatibility and library linking, especially on macOS systems like XAMPP environments.

The attempts to run sudo pecl install libsodium failed because:

  1. PHP Version Mismatch: The specific version of libsodium being compiled conflicted with the installed PHP 8.2.4 environment.
  2. System Library Errors: The configure script failed because it could not find or link necessary underlying system libraries (wrong libsodium lib version), indicating an issue with how PECL interacts with the host operating system.

Practical Solutions for Enabling ext-sodium

Since manual compilation proved frustrating, we need to pivot to more stable methods for enabling core extensions. For a Laravel project, ensuring your environment is correctly configured is crucial, as highlighted by best practices in building scalable applications, much like those promoted by laravelcompany.com.

Here are the most reliable ways to resolve this issue:

Method 1: Using System Package Managers (Recommended)

Instead of relying solely on compiling extensions from source, leverage your operating system's package manager to install necessary PHP modules. This method handles dependencies and compilation much more reliably.

For Debian/Ubuntu-based systems (or environments using apt):
You should install the development packages for Sodium directly through the distribution repositories.

sudo apt update
sudo apt install php8.2-sodium

Note: Replace php8.2 with your specific PHP version if necessary.

For macOS/Homebrew environments:
If you are using Homebrew, installing via Homebrew often manages the required dependencies better than direct PECL compilation. Ensure you have the correct prerequisites installed before attempting to build extensions.

Method 2: Checking and Enabling in php.ini

Even after installation, PHP must be explicitly told to load the extension. After successfully installing the system package (Method 1), locate your php.ini file and ensure the extension is uncommented:

; In php.ini
extension=sodium

After making this change, you must restart your web server (Apache/Nginx) or PHP-FPM service for the changes to take effect.

Conclusion

Encountering dependency issues involving native extensions like ext-sodium is a common hurdle in modern PHP development. The key takeaway is that compiling extensions directly using tools like PECL can be brittle, especially across different operating systems and PHP versions.

For Laravel developers, the most robust approach is to prioritize system-level package management (like apt) to install core dependencies. This ensures that your environment meets the requirements of libraries such as those found in the ecosystem, allowing you to focus on building features rather than wrestling with compilation errors. By ensuring your PHP environment is sound, we can move forward confidently with complex package installations and application development.