apache - PHP upload_max_filesize not obeyed

717

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-- Searchgrep -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
242

Answer

Solution:

If you examine the first few lines of thephpinfo() 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.

682

Answer

Solution:

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

59

Answer

Solution:

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
40

Answer

Solution:

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).

People are also looking for solutions to the problem: PHP SQL Allow empty or numeric input field

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.