3

PHP /etc/php.ini is not obeying upload_max_filesize

Details: using <?php echo phpinfo(); ?> I can see that the 'Loaded Configuration file' is /etc/php.ini

Within this file I have the values:

file_uploads = On
upload_max_filesize = 12M
post_max_size = 12M

BUT the phpinfo(); shows upload_max_filesize 2M

After restarting Apache serveral times this value is never obeyed whatever I change the upload_max_filesize and max_post_size.

I have worked around this issue by using a .htaccess directive

php_value upload_max_filesize 12M
php_value post_max_size 12M

This has allowed the upload value to be changed and the PHPINFO() now shows the value correctly.

Directive            Local Value    Master Value
upload_max_filesize  12M            2M

The question is: why is the /etc/php.ini file not being obeyed in the first place? Running CentOs 5.4 , php 5.3.29 Searched (grep -inr '2M' *) in /etc/php.d/* with nothing found.

Why is it not listening to the main php.ini file which it says it's using?

Already looked at PHP upload_max_filesize

and Changing upload_max_filesize on PHP

on SO with no success.

--UPDATE-- Search grep -inr 'upload_max_filesize in /etc/*.ini and .conf with only the 12M value being returned. Searched /etc/httpd/conf/ /etc/httpd/conf.d/ and obviously the root of the virtual host. No special setup in virtual hosts with grep returning 0 results.

Additional .ini files parsed
    /etc/php.d/bcmath.ini, /etc/php.d/curl.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, 
    /etc/php.d/gd.ini, /etc/php.d/intl.ini, /etc/php.d/json.ini, /etc/php.d/ldap.ini, 
    /etc/php.d/mbstring.ini, /etc/php.d/mcrypt.ini,
/etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini, /etc/php.d/posix.ini, /etc/php.d/soap.ini,    /etc/php.d/suhosin.ini, /etc/php.d/sysvmsg.ini, /etc/php.d/sysvsem.ini, etc/php.d/sysvshm.ini,
/etc/php.d/wddx.ini, /etc/php.d/xdebug.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlwriter.ini,
/etc/php.d/xsl.ini, /etc/php.d/zip.ini
Community
  • 1
  • 1
JI-Web
  • 481
  • 6
  • 27
  • 1
    On the first few line of `phpinfo()` page, it should tell which `php.ini` is being loaded. Search that `php.ini` – Raptor Nov 25 '15 at 02:46
  • 1
    @Raptor : The OP says /etc/php.ini is indeed used. – sjsam Nov 25 '15 at 03:01
  • Oops. I missed that line – Raptor Nov 25 '15 at 03:06
  • @Raptor : Thank you anyway. I overlooked the fact that you can look phpinfo() result to see which .ini is used. – sjsam Nov 25 '15 at 03:15
  • @Raptor : By the way is it possible to have more than one .ini files at the same time. A general one and a customized one which can be used to override the settings of the general one as needed. – sjsam Nov 25 '15 at 05:08
  • Yes, multiple `php.ini` can be used. More often use is, use `.htaccess` to override some INI settings. – Raptor Nov 25 '15 at 06:06

4 Answers4

1

If you examine the first few lines of the phpinfo() you can know
which php.ini is loaded.(courtesy @Raptor)

In your question you have mentioned that /etc/php.ini is indeed the one loaded.

In that case there is a chance that your httpd.conf contains something like below :

php_value upload_max_filesize somevalue

This is a global value which will be applied for all the sites.
I guess it may well override the php.ini settings.

sjsam
  • 21,411
  • 5
  • 55
  • 102
  • Thanks sjsam, I will take a look at the http.conf and other included conf files to see. I did originally look there (php.conf) but couldn't see anything regarding 2MB limitations... Will take a closer look at the apache side – JI-Web Nov 26 '15 at 07:34
  • Hi sjsam, I've looked in /etc/*.ini /etc/*.conf /etc/httpd/conf/* /etc/httpd/conf.d/* and no reference to 'upload_max_filesize'... + also tried /etc/php.d with no success.... – JI-Web Nov 26 '15 at 22:17
0

I had the .htaccess in the root of website overriding this value from php.ini.

ALeX inSide
  • 484
  • 3
  • 10
0

I lost quite a bit of time trying to figure this out as well. Turns out that this will happen if you are using php-fpm. The php.ini file will be read, phpinfo() will tell you that it's been read, but the max filesize value (as well as a few others) will be ignored.

I experienced this with a Centos8 install, and it took me far too long to notice that it was using php-fpm instead of mod_php, so all the arguments to mod_php were being ignored.

Your options are to either install mod_php or just configure php-fpm properly (better).

aeu
  • 141
  • 2
  • 5
0

Try to set in your htaccess file. May be this might help you guys. It's working for me

php_value post_max_size 30M
php_value upload_max_filesize 25M
php_value upload_max_size 25M
Sam
  • 31
  • 2
  • Thanks for the reply. I did write in the post that the .htaccess method is a suitable workaround but it does not explain the question of where/which/why the 2MB is coming from... Anyway, suitable workaround using .htaccess. – JI-Web Oct 07 '20 at 22:44