Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'

Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

The Mcrypt Extension and Laravel on macOS

The error message Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' is a classic symptom of a deprecated PHP extension, not a path configuration issue. While your suspicion about the .bash_profile and the localhost address might seem plausible at first glance, the root cause lies in how PHP handles encryption on modern versions of macOS.

This error occurs because Laravel relies on the mcrypt extension for its default encryption service (the App\Encrypter class often defaults to using Mcrypt if no custom driver is configured). The code in your application attempts to access constants like MCRYPT_RIJNDAEL_128, which were specific to the legacy mcrypt library.

The critical detail here is that Apple removed the libmcrypt library from macOS starting with OS X 10.9 (Mavericks) as part of a security update. Consequently, the mcrypt extension was completely removed from PHP distributions on these systems. Even though you verified via phpinfo() that mcrypt appears to be installed, this is often misleading if you are looking at an older snapshot or if the extension is loaded but missing its underlying system libraries (libmcrypt), causing constants to fail resolution.

Why Your Path Configuration Isn't the Culprit

Your .bash_profile configuration regarding the PATH variable and the need to manually export ~/.composer/vendor/bin suggests a separate issue regarding CLI tool availability, but it does not explain the encryption error. The MCRYPT_RIJNDAEL_128 constant is resolved at runtime by the PHP interpreter itself, which loads extensions based on php.ini, not your shell's binary path.

If you were trying to run a specific executable from a custom directory, that would be a path problem. However, PHP functions and constants are global to the process. The fact that you can access localhost:8000 implies the PHP-FPM or Swoole server is running correctly; it just cannot find the encryption backend defined in your config/app.php.

Migrating Away from Mcrypt

Attempting to "fix" this by reinstalling libmcrypt on macOS is a dead end. Apple does not support this library, and doing so requires complex workarounds that are generally unstable. The standard and supported approach is to migrate Laravel's encryption driver away from the deprecated Mcrypt engine.

You should update your application to use the OpenSSL driver instead. This is not just a workaround; it is the modern standard for PHP encryption. To implement this, modify your config/app.php file. Locate the cipher configuration setting and switch the driver class:

'cipher' => 'AES-256-CBC',
// Or explicitly set the driver if using an older Laravel version that requires it
// 'encrypter' => \Illuminate\Encryption\McryptEncrypter::class, 
// Change to:
// 'encrypter' => \Illuminate\Encryption\OpenSslEncrypter::class,

In newer versions of Laravel (5.8+), this is often handled automatically if the cipher setting is present, but ensuring you are using OpenSSL logic is key. You can verify the available drivers by checking your environment:

php -m | grep openssl

If openssl is listed (which it almost certainly will be on a standard macOS PHP install), you are ready to proceed.

Updating the Application Code

If you have custom encryption logic in your codebase, you must update any direct references to MCRYPT_RIJNDAEL_128. These constants are part of the legacy API and do not exist in the OpenSSL context. Replacing them with the appropriate OpenSSL equivalents or relying on Laravel's unified Illuminate\Encryption facade will resolve the undefined constant error permanently.

Addressing the Environment Variables

While fixing the encryption issue is the priority, your shell configuration needs attention to prevent future friction when switching between local development environments. The command export PATH="~/.composer/vendor/bin:$PATH" adds Composer bin files to your search path. To make this persistent without manual intervention in every new terminal session, append this line to your ~/.zshrc or ~/.bash_profile.

Note that on macOS, the default shell is often zsh rather than bash. If you are using zsh, ensure your export command is placed inside the ~/.zshrc file. This will allow your artisan commands and other tools to run seamlessly regardless of which port or localhost address you target (localhost:8000, localhost:8888, etc.).

Final Considerations

Once you have switched the cipher configuration to use OpenSSL and removed any references to the legacy mcrypt constants, restart your Laravel development server. The error should vanish, and your application will utilize a supported encryption standard compatible with current macOS security policies. This transition eliminates dependency on non-existent Apple libraries and aligns your stack with current PHP version requirements.

Our network