garrettmassey's avatar

PHP7.4 & composer issue with Herd - Allocation of JIT memory failed

We recently inherited a PHP7.4 site, and I'm trying to set up the environment locally so that I can begin working with it, but when I switch my PHP version to 7.4 in Herd, and try to run composer install (or try to run any composer command) I am met with this error:

Fatal error: Uncaught ErrorException: preg_match(): Allocation of JIT memory failed, PCRE JIT will be disabled. This is likely caused by security restrictions. Either grant PHP permission to allocate executable memory, or set pcre.jit=0 in phar:///Users/garrettmassey/Library/Application Support/Herd/bin/composer/vendor/symfony/console/Output/StreamOutput.php:121
Stack trace:
#0 [internal function]: Composer\Util\ErrorHandler::handle(2, 'preg_match(): A...', 'phar:///Users/g...', 121, Array)
#1 phar:///Users/garrettmassey/Library/Application Support/Herd/bin/composer/vendor/symfony/console/Output/StreamOutput.php(121): preg_match('/^((screen|xter...', 'xterm-256color')
#2 phar:///Users/garrettmassey/Library/Application Support/Herd/bin/composer/vendor/symfony/console/Output/StreamOutput.php(51): Symfony\Component\Console\Output\StreamOutput->hasColorSupport()
#3 phar:///Users/garrettmassey/Library/Application Support/Herd/bin/composer/vendor/symfony/console/Output/ConsoleOutput.php(42): Symfony\Component\Console\Output\Str in phar:///Users/garrettmassey/Library/Application Support/Herd/bin/composer/vendor/symfony/console/Output/StreamOutput.php on line 121

So, I checked the .ini for PHP7.4 in Herd, and this is what it shows:

curl.cainfo=/Users/garrettmassey/Library/Application Support/Herd/config/php/cacert.pem
openssl.cafile=/Users/garrettmassey/Library/Application Support/Herd/config/php/cacert.pem
pcre.jit=0
output_buffering=4096

memory_limit=128M
upload_max_filesize=32M
post_max_size=32M

which looks corret, the pcre.jit is set. When I switch back to any PHP8+ version I can run composer, but because this particular site requires 7.4, I get errors stating:

- Root composer.json requires php ^7.4 but your php version (8.2.28) does not satisfy that requirement.

I've restarted Herd several times, but it doesn't seem to work. Not sure where to proceed from here.

0 likes
2 replies
LaryAI's avatar
Level 58

You’re encountering the “Allocation of JIT memory failed, PCRE JIT will be disabled” error, even though you’ve set pcre.jit=0 in your PHP 7.4 ini file in Herd. Here are a few things you can try to resolve this issue:


1. Double-check the Correct php.ini Location

Herd can use custom configuration files for different PHP versions. Composer may be using a different php.ini than you think. Find out which ini PHP CLI uses:

php -i | grep "Loaded Configuration File"

Make sure that this file has pcre.jit=0 set, not just an ini you edited elsewhere.


2. Set pcre.jit=0 via Command Line as a Test

To ensure the setting is applied, let’s try running Composer with the ini setting overridden:

php -d pcre.jit=0 /path/to/composer install

If you’re using Herd’s global Composer installation, adjust path accordingly:
For example:

php -d pcre.jit=0 "$(which composer)" install

If this works, it means your ini file is not being picked up as you expect.


3. Environment/Container Security Restrictions

If Herd is using some sort of sandbox, the system security (like macOS SIP, AppArmor, or SELinux) may block allocating executable memory. You can often work around this by fully disabling JIT (which you tried) or by running Composer with less isolation (not applicable unless using something like Docker).


4. Export Environment Variable

Some people have reported improved reliability by setting an environment variable before running Composer:

export PCRE_JIT=0

Then run your Composer command.


5. Clear and Restart Herd

After changing any .ini files, always restart Herd to ensure it reloads your changes.
If you did this, try a full system reboot as well.


6. Verify Herd is Actually Switching PHP Versions

Sometimes GUI tools like Herd appear to switch PHP versions, but the terminal still uses the system’s PHP.

Check by running:

php -v
which php

Make sure both refer to Herd’s PHP 7.4.


7. Try Composer as a Local PHAR

To rule out issues with Herd’s Composer, try downloading Composer as a PHAR in your project directory:

php -d pcre.jit=0 composer.phar install

Summary

  • Double-check the exact php.ini used by CLI (php -i | grep ini).
  • Try forcing pcre.jit=0 via the -d CLI flag.
  • Make sure you’re using Herd’s PHP everywhere.
  • Set the environment variable if needed.
  • If all else fails, try Composer from a standalone PHAR.

If all the above fails, please share the full output of php -i, and specify if you're running on Intel Mac or Apple Silicon, as certain low-level issues may affect this as well.


Let me know which of these resolves it!

Please or to participate in this conversation.