My開発メモ

Warning: preg_match(): Allocation of JIT memory failed, PCRE JIT will be disabled.(WordPress MacOS/Ventura)

経過

MacOS/Ventura 13.4.1 で
以下の環境に WordPress-6.3.1 をインストールした。

WordPressは、~/Sites/Documents 直下に入れた。
(僕は VirtualHost を有効にし、自ホームを userdir としている。)

(参考) Apacheでバーチャルホストを立ち上げる(mac/Monterey)

% httpd -v
Server version: Apache/2.4.56 (Unix)

% php -v
PHP 8.2.10 (cli) (built: Aug 31 2023 18:52:55) (NTS)

% mysql --version
mysql  Ver 8.1.0 for macos13.3 on arm64 (Homebrew)

データベースを用意して
http://localhost/
とすると、以下の警告が出た。

Warning: 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 /Users/seiichinukayama/Sites/Documents/wp-includes/load.php on line 46

警告: preg_match(): JIT メモリの割り当てに失敗しました。PCRE JIT は無効になります。 これはセキュリティ制限が原因である可能性があります。 実行可能メモリを割り当てるための PHP 権限を付与するか、/Users/seiichinukayama/Sites/Documents/wp-includes/load.php の 46 行目で pcre.jit=0 を設定します。

wp-include/load.php の 46行目は、こんなんやけど。

44	// Fix for IIS when running with PHP ISAPI.
45	if ( empty( $_SERVER['REQUEST_URI'] )
46		|| ( 'cgi-fcgi' !== PHP_SAPI && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) )
47	) {

IIS向けの設定?

“stack overflow” では、こんな回答があった。

You should be able to ward off this warning by using ini_set to change the config value suggested by the warning message itself:
ini_set(“pcre.jit”, “0”);
Be sure to run that line of code before any usages of regular expressions.

ini_set を使用して、警告メッセージ自体が示唆する設定値を変更することで、この警告を回避できるはずです。
ini_set(“pcre.jit”, “0”);
正規表現を使用する前に、必ずそのコード行を実行してください。

https://stackoverflow.com/questions/59231779/allocation-of-jit-
memory-failed-pcre-jit-will-be-disabled-warning-in-php-7

wordpress.org のサポートにも、よく似た質問が寄せられていて、
サポート担当者の回答は、”php.ini に pcre.jit = 0 と記入してくれ” と
いうものだった。

wordpress.org / support

PCRE とは Perl compatible regular expression で、
JIT とは Just in time のことみたい。

Innovator Japan Engineers’ Blog

PCRE.JIT を無効にすると、正規表現のパフォーマンスが落ちるみたいで、よろしくないらしい。

php.ini を確認してみると、pcre.jit は コメントアウトされている。

% less /opt/homebrew/etc/php/8.2/php.ini

1059 ;pcre.jit=1

これで、 phpinfo() を確認すると、PCRE.JIT は ON になっている。

php.ini を pcre.jit=0 とすると、WordPressでは確かに警告は出なくなる。

が、WordPressのために phpの処理を遅くするのもなんだし。

対策

wp-config.php に以下の記述を入れてみた。

% vi ~/Sites/Documents/wp-config.php
/* Add any custom values between this line and the "stop editing" line. */

ini_set("pcre.jit", "0");

それから、Apacheを再起動。

% sudo apachectl restart

こうすることで、WordPressが動いているときだけ、PCRE.JITを無効に
できる。

カテゴリー: Apache, MacOS, memo, php, wordpress

タグ: PCRE.JIT

カウント: 175