6

I just installed Opcache and everything seems working just fine, but when I add a PHP file in opcache.preload in php.ini and restart the Apache server doesn't start. On the other hand, In CLI SAPI preloading works fine!

When I comment out opcache.preload and restart, the Apache server works

Since this issue is not emitting any error I looked up Apache error_log file and it turns out the issue was me not defining the opcahe preload user

Fatal Error "opcache.preload_user" has not been defined

But according to PHP documentation

Preloading code as root is not allowed for security reasons. This directive facilitates to let the preloading to be run as another user.

I'm working on my personal computer running Ubuntu under WSL

So please guide me what should I do? what user should I add?

2
  • Are you sure using php7.4-fpm for apache2? Dec 13, 2019 at 12:30
  • I am not sure, but that was a reason on my server php (for apache) was not working at all. Dec 13, 2019 at 12:47

1 Answer 1

9

The default user for web servers on Ubuntu is www-data

All you need to do is

opcache.preload_user=www-data

And if you want to check preloading

var_dump(opcache_get_status()['preload_statistics']); 

It will list all preloaded files as well as the memory consumed by them

As for why Apache refuses to start when I don't define a preload user?

I actually don't know why. It might be a bug, not sure though.


While the statement from PHP documentation is not complete, but note that:

Preloading under root is not allowed by default, but explicit use of opcache.preload_user=root is allowed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.