Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache doesn't start when there's a preloaded file

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?

like image 765
Rain Avatar asked Dec 13 '19 12:12

Rain


1 Answers

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

  • Nikic
like image 75
Rain Avatar answered Oct 20 '22 14:10

Rain