php 7 php.ini upload_max_filesize not working
Asked Answered
C

16

33

I have read many solutions on internet , but still cannot change upload_max_filesize value (upload_max_filesize always = 2M )

here is my loaded php.ini in phpinfo() :

Configuration File (php.ini) Path         /etc/php/7.0/apache2
Loaded Configuration File                    /etc/php/7.0/apache2/php.ini
Scan this dir for additional .ini files      /etc/php/7.0/apache2/conf.d 
upload_max_filesize 2M  2M
post_max_size   8M  8M

here is my edited php.ini in /etc/php/7.0/apache2/php.ini

; http://php.net/post-max-size
post_max_size = 86M
; http://php.net/upload-max-filesize
upload_max_filesize = 40M

im using ubuntu 14.04,apache2,php7.0 (I have reset apache2 many time after each change in php.ini )

Chemical answered 23/5, 2016 at 1:43 Comment(7)
You need to check the path of php.ini, it seems you are making changes somewhere else. You can see the ini path in phpinfo itself just check for the row 'Configuration File (php.ini) Path'Apocarpous
i changed every php.ini file i found , but still cannot change upload_max_filesize :(Chemical
Restart the server and check for the changes.Apocarpous
i have restart apache2 many times,but it still the same ...Chemical
php -i | grep -i "upload\_max\_filesize\|post\_max\_size\|max\_file\_uploads" is a helpful command that can help you catch that maybe whatever "ini" file you updated either hasn't been reloaded or might not be the correct file in use at all.Supermundane
See #48601691Supermundane
I couldn't get a file to upload through a wordpress site even though I checked all php.ini files & did everything I could think of serverside. Turned out it was a wordpress multi-site network setting. /wp-admin/network/settings.phpMimetic
C
22

i fingured out !

in my loaded php.ini config , my error_reporting values is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED-> this is wrong!, so i changed it to

error_reporting: E_ALL and then restart apache2 server, now everything working fine !


so please note : if php.ini have any error , it will use default value (which means upload_max_filesize always 2M )

Chemical answered 25/5, 2016 at 3:18 Comment(6)
This was the reason. Fixed my case.Lecythus
this worked, thanks. I think this is very unintuitive, i was very lucky to find your solution.Dartboard
@Chemical thank you but I still need to see my errors, how can I do that? I still get 2M though I changed my valueWebster
@AbeerSul did you restart the web server?Chemical
@Chemical yes but it didn't fix it, thank you I finally was able to fix here #67967782Webster
@AbeerSul gut to know ^^Chemical
A
53

I had a fix for PHP-FPM 7.1

Edit your php.ini in

/etc/php/7.1/fpm/php.ini

Make changes to whatever option you want like, post_max_size, upload_max_filesize, max_execution_time & so...

save & close file.

run

sudo service php7.1-fpm restart

It will work!

Ammadas answered 3/2, 2018 at 19:33 Comment(4)
For me, it was this simple - and it's logical. We have changed PHP variables, not Apache2. So restarting PHP is all that was needed!Boehmite
Of course! You have to restart FPM! Thank you so much! Just needed to recall thatPetiolate
Thank! I am so used to running as MPM where all you need is to restart apache, but since switching to FPM (for http/2 support), I didn't realize that you needed to restart FPM directly.Calen
In my case, I just needed to edit /etc/php.ini, restart httpd. I checked for the php process (ps ax | grep -i php) and restarted that: systemctl restart php-fpm This is on CentOS Stream.Feuchtwanger
S
26

I had an other fix for it. os: ubuntu 16.04 phpversion: 7.0

I created a phpinfo.php file containing:

<?php phpinfo() ?>

place the phpinfo.php file in the root of your website www.mywebsite.com/phpinfo.php

Navigating to it and lookup the line:

Loaded Configuration File : /etc/php/7.0/cgi/php.ini

Now you know what php.ini file is loaded.

ssh into the server and use your favorite editing tool (mine is nano) to adjust the php.ini

change the values to meet your preferences.

post_max_size = 128M

upload_max_filesize = 64M

Save and close the file.

Restart apache

sudo service apache2 restart

__

check the phpinfo.ini if the new values are as set.

and if they do you are set to go.

Shoifet answered 9/11, 2016 at 14:58 Comment(2)
/etc/php/7.0/cgi/php.ini should be /etc/php/7.0/cli/php.ini. There is no cgi dir in default php installationUnicuspid
ah some1 alr answer 😂yes correct , just look on phpinfo(); today i wrong path by using on php --ini i think ...Quaint
C
22

i fingured out !

in my loaded php.ini config , my error_reporting values is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED-> this is wrong!, so i changed it to

error_reporting: E_ALL and then restart apache2 server, now everything working fine !


so please note : if php.ini have any error , it will use default value (which means upload_max_filesize always 2M )

Chemical answered 25/5, 2016 at 3:18 Comment(6)
This was the reason. Fixed my case.Lecythus
this worked, thanks. I think this is very unintuitive, i was very lucky to find your solution.Dartboard
@Chemical thank you but I still need to see my errors, how can I do that? I still get 2M though I changed my valueWebster
@AbeerSul did you restart the web server?Chemical
@Chemical yes but it didn't fix it, thank you I finally was able to fix here #67967782Webster
@AbeerSul gut to know ^^Chemical
R
10

For php7.2-fpm

Ubuntu php-fpm located at /etc/php/7.2/fpm so

  1. cd /etc/php/7.2/fpm
  2. sudo nano php.ini
  3. Search for post_max_size = 512M and add your fav size that you really needed
  4. Search for upload_max_filesize = 512M and add your fav size that you really needed
  5. Save File
  6. And Last DO NOT FORGET TO RESTART PHP7.2-FPM to restart sudo service php7.2-fpm restart

Thats all!

Rodmur answered 16/9, 2019 at 18:26 Comment(1)
that sudo service php7.2-fpm restart saved my lifeCelia
U
7

I am using Nginx and my solution was to restart php-fpm.

Restarting Nginx didn't do anything.

sudo service php7.2-fpm restart
Unsophisticated answered 13/5, 2019 at 15:47 Comment(1)
This worked for me! Thank you! I'm using apache and recently moved to php-fpm - I had no idea it was a separate service!Hobbs
B
6

I also found that restarting the httpd service didn't pick up changes in the loaded configuration file (/etc/php.ini on Fedora 29). It's worth listing all systemd units and doing a grep for the string "php":

# systemctl list-unit-files | grep php
php-fpm.service

Restarting php-fpm did the trick for me:

# systemctl restart php-fpm
Bluff answered 22/1, 2019 at 13:5 Comment(0)
P
4

After spending hours reading forum I've resolved this way:

cd /etc/php
find . -name "*.ini" | xargs grep -il upload_max_filesize
./7.1/apache2/php.ini
./7.1/mods-available/better.ini
./7.1/cgi/php.ini
./7.1/cli/php.ini
./7.1/phpdbg/php.ini
./7.1/fpm/conf.d/20-better.ini
./7.1/fpm/php.ini
./7.1/embed/php.ini

change upload_max_filesize in ./7.1/fpm/conf.d/20-better.ini then

/etc/init.d/php7.1-fpm restart

now phpinfo reports: upload_max_filesize 10G 10G

Hope this helps.

Pardew answered 18/6, 2019 at 15:29 Comment(1)
This is the best answer when you are not sure about what version/config you have.Antares
G
4

i also had this problem!

if you are using php-fpm service need to find php-fpm.conf and add line

php_admin_value[upload_max_filesize] = 100M

for changing other type of values

#just for example
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
Guarded answered 7/9, 2019 at 9:58 Comment(1)
This should be chosen as best answer for who ever run using FPM sockNeuromuscular
K
1

Most people are forgetting to restart their php via the terminal that's why it isn't working, if you think you've done everything correctly be sure to restart your php & the server.

Kira answered 15/4, 2018 at 22:47 Comment(0)
E
1

Yeah, Actually I forgot to restart correctly.

sudo service apache2 restart is not enough

first add the configurations to /etc/php/7.1/fpm/php.ini and to /etc/php/7.1/cli/php.ini
#/php/ - then your php version here instead "7.1" ACtually one of these configuration file is the active one (if you want to see what use <?php phpinfo() ?> command in indextest.php file and check it on browser) Then change these parameters on each file with what you want:

post_max_size = 512M
upload_max_filesize = 512M

And then use following command to restart the php server:

sudo service php7.0-fpm restart #php<then your php version here> instead "7.0"

or

sudo /etc/init.d/php7.1-fpm restart  #php<then your php version here> instead "7.1"

Now you should be able to see the changes of upload size. Cheers !

as shown in here you can get to know more about the php server controlls :

$ sudo service php7.0-fpmstart # <- restart it
$ sudo service php7.0-fpm stop # <- restart it
$ sudo service php7.0-fpm restart # <- restart it
$ sudo service php7.0-fpm reload # <- reload it
Enow answered 19/11, 2018 at 18:51 Comment(1)
sudo /etc/init.d/php7.1-fpm restart fixed my issueRebound
F
1

create two different files in the root of your project(if you are a Wordpress user,it is the root public_html folder).one is php.ini & the second one is .user.ini and then simply add these two lines of codes in both files.

upload_max_filesize = 20M
post_max_size = 20M

don't forget to restart the server. and also make sure the user.ini file must be starting with a dot (.)

systemctl restart apache2
Friedland answered 30/3, 2022 at 10:28 Comment(0)
Y
1

In my case I was editing the wrong one. It turns out I should mondify this /etc/php/7.2/apache2/php.ini After doing so, it worked!

Yaws answered 1/5, 2022 at 11:37 Comment(0)
M
0

For those who have all the obvious settings mentioned in other answers and PHP file uploads are stil not working.

Check php.ini for open_basedir value. If a value is set (which it should be for security reasons), make sure that /tmp is included there. Or choose a custom value in upload_tmp_dir and set open_basedir accordingly.

Then reload the FPM service.

Marconigraph answered 1/10, 2019 at 14:54 Comment(0)
P
0

I installed multiple versions of PHP on MacOS Big Sur following the steps here

I used command:

sudo /usr/local/bin/httpd -k restart

to load changes made to the php.ini file.

Pleuropneumonia answered 10/10, 2021 at 18:32 Comment(0)
G
0

open your putty or bitvise ssh client login your server

sudo apt update

After that

cd /etc/php/7.4/apache2/

see the list to hit command below

ls -ltr

output

total 76
drwxr-xr-x 2 root root  4096 Sep  4 14:31 conf.d
-rw-r--r-- 1 root root 72540 Sep  7 09:28 php.ini

to open php.ini enter the below command

 sudo nano php.ini

Move down Arow till not find the Below code

upload_max_filesize = 20M

change 20MB to your desired upload size Press ctrl+s to save php.ini and exit to the editor to command prompt hot ctrl+x after that to reload apache2 hit the below command

sudo systemctl reload apache2

Happy coding

Guienne answered 7/9, 2022 at 11:48 Comment(0)
A
0

For macos, check if you have a php-memory-limits.ini file under /opt/homebrew/etc/php/8.1/conf.d folder,

You need to update upload_max_filesize value in there too!

Arawakan answered 7/3, 2023 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.