Enable PHP8.2 Jit on Ubuntu

With the realease of PHP 8, Just-In-Time compilation (JIT) has been supported. However JIT is not enabled by default. So this post will talk about how to enable JIT with PHP 8.2.

After install PHP, we have the version of 8.2 like this:

PHP 8.2

Next, install the opcache extension by:

1
2
sudo apt update -y
sudo apt install php8.2-opcache

Then, to enable JIT, i was expecting that the configuration of JIT was also in the php.ini. I change it as below:

1
2
3
4
5
6
7
8
$ sudo vim /etc/php/8.2/fpm/php.ini

...
[opcache]
opcache.enable=1
opcache.jit=1255
opcache.jit_buffer_size=100M
...

Restarted the PHP-FPM and checked the phpinfo():

It was stranged that the JIT was not enabled as expected. It seems that the configuration did not worked.

There are lots of posts talking about how to enable the JIT in PHP, but quite a few blogs that introduce while file can be configured for the JIT. After read the JUNDAT95’s post, I found that JIT should configured in a single file which was called opcache.ini. In my server (Ubuntu, PHP 8.2), the file was located in /etc/php/8.2/mods-available/opcache.ini, add the commands in this file:

1
2
3
4
// /etc/php/8.2/mods-available/opcache.ini
...
opcache.jit=1255
opcache.jit_buffer_size=100M

Restart FPM and echo the phpinfo() again, it showed that JIT was enabled successfully.