Search code examples
phplinuxlaravelnginxfile-upload

Why is PHP not allowing me to upload more than 2MB file?


I can't upload an image more than 2MB in my website form.

I have set up the needed settings in /etc/php/7.4/fpm/php.ini:

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 100M  

.
.

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = ON
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

.
.

; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit = 128M 

But the problem is that when I print php info in my index page I get different output :/

enter image description here

enter image description here

enter image description here

Why is this happening and how can I fix it?

NOTE: I'm serving my website with nginx if it matters (see nginx settings) enter image description here


Solution

  • Finally issue fixed:

    the solution was to add php.ini and .user.ini files in the project's public directory to set the needed values (both files):

    upload_max_filesize = 20M
    post_max_size = 20M
    

    like this:

    enter image description here

    I didn't find the real reason why updating /etc/php/7.4/fpm/php.ini but these 2 files finally fixed it