WordPress Ignoring .user.ini
I have a server using Apache and PHP-FPM. The server hosts several WordPress sites with each site running as a different user and using a different pool.
I'm trying to configure the post_max_size
and upload_max_filesize
directives on a per-site basis by placing a .user.ini
file in each site's document root. I know that the .user.ini
file is being read because phpinfo()
displays local values from the .user.ini
file and master values from the main php.ini
file. I've confirmed this using ini_get('post_max_size')
and ini_get('upload_max_filesize')
which both return the local values from the .user.ini
file.
WordPress however, appears to ignore the .user.ini
file. Plugins such as WP-ServerInfo and WP Server Stats display local and master values as the same, with the values coming from php.ini
. I've confirmed this with ini_get()
from within WordPress and Media Add New Maximum upload file size: 2 MB.
.user.ini
is owned by the user running WordPress with 640 permissions.
Directive | .user.ini | php.ini | phpinfo() | phpinfo() | WP Plugin | WP Plugin |
---|---|---|---|---|---|---|
Local | Master | Local | Master | Local | Master | |
post_max_size | 64M | 8M | 64M | 8M | 8M | 8M |
upload_max_filesize | 32M | 2M | 32M | 2M | 2M | 2M |
I know it's possible to set directives on a per-pool basis using php_value
or php_admin_value
, but I'm interested to understand (and a little frustrated) why WordPress appears to be ignoring .user.ini
.
Any insights are greatly appreciated.
Many thanks.
UPDATE:
The comment from @TomJNowell got me thinking. I did a search on what PHP CGI/FPM is passing to WordPress and found this post describing a similar issue with the Wordfence plugin.
I followed the suggestion of moving .user.ini
from the document root to the /wp-admin
directory. WordPress now gets passed the values in .user.ini
. Conversely, phpinfo()
doesn't get these values as it's in a script run from the document root, which makes sense.
Directive | .user.ini | php.ini | phpinfo() | phpinfo() | WP Plugin | WP Plugin |
---|---|---|---|---|---|---|
Local | Master | Local | Master | Local | Master | |
post_max_size | 64M | 8M | 8M | 8M | 64M | 8M |
upload_max_filesize | 32M | 2M | 2M | 2M | 32M | 2M |
The post went on to suggest moving .user.ini
back to the document root then creating a symlink to it in the /wp-admin
directory. Now both WordPress and phpinfo()
get the values from .user.ini
.
Directive | .user.ini | php.ini | phpinfo() | phpinfo() | WP Plugin | WP Plugin |
---|---|---|---|---|---|---|
Local | Master | Local | Master | Local | Master | |
post_max_size | 64M | 8M | 64M | 8M | 64M | 8M |
upload_max_filesize | 32M | 2M | 32M | 2M | 32M | 2M |
Not sure this last step is strictly necessary as the directives are for the benefit of WordPress, but it does tie-it-up neatly.
I'm also unsure why my original setup doesn't work, but having .user.ini
(or a symlink to it) in the /wp-admin
directory does. Maybe this is more of a hack than the correct way of doing it, but I'm content for now that it works.
Topic php.ini configuration php Wordpress
Category Web