Max filesize not taking effect from php.ini - php

I know this is a massive repost but I couldn't figure this out. The server is Ubuntu using nginx.
Doing phpinfo() I see the configuration file I am using is /etc/php/7.0/fpm/php.ini.
These are the properties I set:
upload_max_filesize = 256M
post_max_size = 256M
I restarted nginx, as well as the php7.0-fpm process and the max upload size is still not changing.
I am using wordpress so as a last resort I even tried using a plugin that increases the max upload size and even that didn't work.
I also tried setting it in my .htaccess as well and still nothing:
php_value post_max_size 256M
php_value uploads_max_filesize 256M

By default NGINX has a limit of 1MB on file uploads. To change this you will need to set the client_max_body_size variable. You can do this in the http block in your nginx.conf
http {
#...
client_max_body_size 100m;
client_body_timeout 120s; # Default is 60, May need to be increased for very large uploads
#...
}
If you are expecting upload very large files where upload times will exceed 60 seconds you will also need to add the client_body_timeout variable with a large value
After updating you NGINX configuration don’t forget to restart NGINX.
you need to restart nginx and php to reload the configs. This can be done using the following commands;
sudo service nginx restart
sudo service php7.0-fpm restart
Note:if you don't have to host multiple
Websites just add it to the server block
server {
client_max_body_size 8M;
}

The answer I found here:
Have you tried to put your php.ini under /etc/php5/fpm/php.ini? This is normally the default location that php reads from, if I understand php5-fpm correctly.

A couple of things.
When you mention that your server uses nginx it is unnecesary to use an .htaccess file since those are for Apache servers.
That being said, I would try a couple of things.
Do you know what's the ini file of your php instance?
You mention the one for php 7 but you could also have php 5 installed.
If you go to your console and type "php --ini" what's the loaded configuration file?
Once you know that, using vi / vim or your editor of choice you can set:
upload_max_filesize = 100M
post_max_size = 100M
Now, have into account that you have to restart your services, both php and nginx:
for php 5:
service php5-fpm reload
for php 7:
service php7-fpm reload
for nginx:
service nginx reload
try printing the current values as well:
$uploadMaxFilesize = ini_get('upload_max_filesize');
$postMaxSize = ini_get('post_max_size');
Also, since this is for WordPress, did you try setting it up in the WordPress admin settings?
Admin Dashboard > Settings > Upload Settings

There's a couple things I had to change to get it working for me.
Firstly from user NID here, add this to your /etc/nginx/nginx.conf file (inside the http block):
http {
#...
client_max_body_size 100m;
client_body_timeout 120s; # Default is 60, May need to be increased for very large uploads
#...
}
Then I also had to follow something similar to user Just Rudy here.
Edit your php.ini file - contrary to many guides, for me it was not located in my wordpress root folder, but instead, /etc/php/7.2/fpm/php.ini.
There should be some predefined values for upload_max_filesize and post_max_size. Change these to what you want.
Restart nginx and php-fpm:
sudo systemctl reload nginx
sudo systemctl restart php7.2-fpm

Related

413 Request Entity Too Large nginx server in laravel while uploading video file

I am trying to upload video files of around 150MB via my project.
and I get the error 413 Request Entity Too Large nginx every-time I try
as per some of the articles I found I changed my nginx.conf in aws server as below
sudo nano /etc/nginx/nginx.conf
Then add a line in the http section
http {
client_max_body_size 500M;
}
sudo system restart nginx
then for php location
sudo nano /etc/php/7.4/fpm/php.ini
couldn't find this file but I have updated
post_max_size and upload size to 500M in php.ini and it's updated when I check phpinfo(); in my project
memory_limit = 500M
post_max_size = 500M
upload_max_filesize = 500M
restarted nginx
stopped & restarted as well
sudo service nginx restart
Still couldn't find a solution.
please help me out with it
Thanks & Regards

Nginx, PHP and centos7 error 413-request-entity-too-large when connect to different network

My web system (Laravel) had 2 domain which company.test.hero (which can only be access by my company network) and example.com (which point to company.test.hero and can be access by public)
The problem is when I want to upload file, if I connect to my company network I can upload file without problem.
But if I connect with other network, it will give Error 413-request-entity-too-large (I try to upload file size 2.86mb).
I already setting NGINX upload limit in folder etc>nginx>nginx.conf
client_max_body_size 20M;
I also had set etc>php.ini upload limit.
upload_max_filesize = 20M
memory_limit = 256M
post_max_size 20M
Edit your NGiNX configuration file (usually /etc/nginx/nginx.conf) and add this line into the http section:
http {
client_max_body_size 100M;
}
Note: Don't use MB, use only M or it will not work!
Also do not forget to restart nginx:
systemctl restart nginx

413 Request Entity Too Large

I use nginX/1.6 and laravel when i posted data to server i get this error 413 Request Entity Too Large. i tried many solutions as bellow
1- set client_max_body_size 100m; in server and location and http in nginx.conf.
2- set upload_max_filesize = 100m in php.ini
3- set post_max_size = 100m in php.ini
After restarting php5-fpm and nginx the problem still not solved
Add ‘client_max_body_size xxM’ inside the http section in /etc/nginx/nginx.conf, where xx is the size (in megabytes) that you want to allow.
http {
client_max_body_size 20M;
}
I had the same issue but in docker. when I faced this issue, added client_max_body_size 120M; to my Nginx server configuration,
nginx default configuration file path is /etc/nginx/conf.d/default.conf
server {
client_max_body_size 120M;
...
it resizes max body size to 120 megabytes. pay attention to where you put client_max_body_size, because it effects on its scope. for example if you put client_max_body_size in a location scope, only the location scope will be effected with.
after that, I did add these three lines to my PHP docker file
RUN echo "max_file_uploads=100" >> /usr/local/etc/php/conf.d/docker-php-ext-max_file_uploads.ini
RUN echo "post_max_size=120M" >> /usr/local/etc/php/conf.d/docker-php-ext-post_max_size.ini
RUN echo "upload_max_filesize=120M" >> /usr/local/etc/php/conf.d/docker-php-ext-upload_max_filesize.ini
since docker PHP image automatically includes all setting files from the path (/usr/local/etc/php/conf.d/) into php.ini file, PHP configuration file will change by these three lines and the issue must disappear
I am using Docker and PHP 7.4 and I faced this issue too.
Just added a line to the file *.conf inside docker/php74/ directory.
server {
client_max_body_size 100M;
...
}

413 Request Entity Too Large - File Upload Issue

I am trying to upload 30MB file on my server and its not working.
When I upload 30MB file, the page loads "Page Not Found"
When I upload a 3MB file, I receive "413 Request Entity Too Large" with nginx/0.6.32
I am trying to find nginx so I can increase "client_max_body_size" but I am unable to find nginx installed on my server. I even tried running:
vi /etc/nginx/nginx.conf
or
vi /usr/local/nginx/conf/nginx.conf
to check if the config file exists, but I couldnt find it on my server.
Is there anyway to resolve this issue? Or do I have to installed nginx on my server.
EDIT:
I have made all necessary changes in my php.ini files,
post_max_size 128M
upload_max_filesize 100M
memory_limit 256M
Thanks,
Raju
Source:
http://www.cyberciti.biz/faq/linux-unix-bsd-nginx-413-request-entity-too-large/
Edit the conf file of nginx:
nano /etc/nginx/nginx.conf
Add a line in the http, server or location section:
client_max_body_size 100M;
Doen't use MB it will not work, only the M!
Also do not forget to restart nginx
systemctl restart nginx
-in php.ini (inside /etc/php.ini)
max_input_time = 24000
max_execution_time = 24000
upload_max_filesize = 12000M
post_max_size = 24000M
memory_limit = 12000M
-in nginx.conf(inside /opt/nginx/conf)
client_max_body_size 24000M
Its working for my case
First edit the Nginx configuration file (nginx.conf)
Location: sudo nano /etc/nginx/nginx.conf
Add following codes:
http {
client_max_body_size 100M;
}
Then Add the following lines in PHP configuration file(php.ini)
Location: sudo gedit /etc/php5/fpm/php.ini
Add following codes:
memory_limit = 128M
post_max_size = 20M
upload_max_filesize = 10M
sudo nano /etc/nginx/nginx.conf
Then add a line in the http section
http {
client_max_body_size 100M;
}
don't use MB only M.
systemctl restart nginx
then for php location
sudo gedit /etc/php5/fpm/php.ini
for nowdays maximum use php 7.0 or higher
sudo nano /etc/php/7.2/fpm/php.ini //7.3,7.2 or 7.1 which php you use
check those increasing by your desire .
memory_limit = 128M
post_max_size = 20M
upload_max_filesize = 10M
restart php-fpm
service php-fpm restart
I add the changes directly to my virtualhost instead the global config of nginx, like this:
server {
client_max_body_size 100M;
...
}
And then I change the params in php.ini, like the comments above:
max_input_time = 24000
max_execution_time = 24000
upload_max_filesize = 12000M
post_max_size = 24000M
memory_limit = 12000M
and what you can not forget is to restart nginx and php-fpm, in centos 7 is like this:
systemctl restart nginx
systemctl restart php-fpm
Please enter domain nginx file :
nano /etc/nginx/sites-available/domain.set
Add to file this code
client_max_body_size 24000M;
If you get error use this command
nginx -t
I got the same error and fixed it with the below steps.
At first, edit the nginx.conf file.
vi /etc/nginx/nginx.conf
At the HTTP section, added the below line.
http {
client_max_body_size 100M;
}
Finally restarted Nginx with the below command.
systemctl restart nginx
Assuming that you made the necessary changes in your php.ini files:
You can resolve the issue by adding the following line in your nginx.conf file found in the following path:
/etc/nginx/nginx.conf
then edit the file using vim text editor as follows:
vi /etc/nginx/nginx.conf
and add client_max_body_size with a large enough value, for example:
client_max_body_size 20MB;
After that make sure you save using :xi or :wq
And then restart your nginx.
That's it.
Worked for me, hope this helps.
I got the upload working with above changes. But when I made the changes I started getting 404 response in file upload which lead me to do further debugging and figured out its a permission issue by checking nginx error.log
Solution:
Check the current user and group ownership on /var/lib/nginx.
$ ls -ld /var/lib/nginx
drwx------. 3 nginx nginx 17 Oct 5 19:31 /var/lib/nginx
This tells that a possibly non-existent user and group named nginx owns this folder. This is preventing file uploading.
In my case, the username mentioned in "/etc/nginx/nginx.conf" was
user vagrant;
Change the folder ownership to the user defined in nginx.conf in this case vagrant.
$ sudo chown -Rf vagrant:vagrant /var/lib/nginx
Verify that it actually changed.
$ ls -ld /var/lib/nginx
drwx------. 3 vagrant vagrant 17 Oct 5 19:31 /var/lib/nginx
Reload nginx and php-fpm for safer sade.
$ sudo service nginx reload
$ sudo service php-fpm reload
The permission denied error should now go away. Check the error.log (based on nginx.conf error_log location).
$ sudo nano /path/to/nginx/error.log
Anyone looking for a solution for Apache2 (Ubuntu 18 for me), you can edit:
/etc/apache2/apache2.conf
And find/edit the line:
LimitRequestBody 7000000 #7mb
In my case, I was using nginx along with letsencrypt to put a ssl layer in front of my spring boot application.
Putting clint_max_body_size property in "/etc/nginx/nginx.conf" did not work for me.
Instead, I put this property inside the site specific conf file.
sudo nano /etc/nginx/sites-available/mywebsite.com
server {
...
client_max_body_size 3M;
...
}
Post saving the above, restarted the nginx server and it worked !
sudo service nginx stop
sudo service nginx start
Open file/etc/nginx/nginx.conf
Add or change client_max_body_size 0;
Use:
php -i
command or add:
phpinfo();
to get the location of configuration file.
Update these variables according to your need and server
max_input_time = 24000
max_execution_time = 24000
upload_max_filesize = 12000M
post_max_size = 24000M
memory_limit = 12000M
On Linux you will need to restart nginx / apache and phpfpm service so the new ini settings are loaded. On xampp, ammps you can restart these from control panel that comes with such applications.
Just open this file and ---
sudo vim /etc/nginx/nginx.conf
Add a line in the http, server or location section:
client_max_body_size 100M;
Then check nginx is okey or not by the following command
sudo nginx -t
If everything looks fine then you will get
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Then restart nginx
sudo systemctl restart nginx
I hope your purpose is served :)

php nginx max upload file size - unusual case

I was going through number of pages in google and pretty much all answers associated with this in stackoverflow, bus still, can not get this thing working.
I can upload smaller then 2M files, but not any larger.
I am running Centos 6.2 with PHP-FPM (PHP 5.3.10) and NGINX (nginx version: nginx/1.0.12).
Now I got client_max_body_size 10M; in nginx.conf, in the http section.
I also got upload_max_filesize = 8M , post_max_size = 8M , memory_limit = 128M
usually in almost any answer to this question I have met, these changes helps for users.
Now I done some research, and made this script:
<?php
//ini_set('upload_max_filesize', '8M');
$max_upload = (ini_get('upload_max_filesize'));
$max_post = (ini_get('post_max_size'));
$memory_limit = (int) (ini_get('memory_limit'));
echo ('$max_upload ' . $max_upload);
echo ('$max_post ' . $max_post);
echo ('$memory_limit ' . $memory_limit);
?>
Now If I run in in server terminal - i get $max_upload 8M $max_post 8M $memory_limit 128
But if I run it via webserver (NGINX) - I get $max_upload 2M $max_post 8M $memory_limit 128
So my assumption is that its NGINXes problem, but yet again the only NGINX parameter regarding this matter is client_max_body_size 10M; , which is sec correctly and is placed in the right place in the config.
I am sorry if this is something obvious, or if there is something I have missed, would be glad if someone would point me to the right direction.
Cheers !
EDIT:
So we solved it with AlexeyKa's help. We looked up in phpinfo, and there it said that php was using different php.ini file. Some time ago I made a copy of php.ini into my home directory. And it turnes out that when (some time ago) I restarted php-fpm, it switched from /etc/php.ini file to /home/my-user/php.ini file. Essentially I renamed the /home/my-user/php.ini and restarted the php-fpm. This solved everything, as it switched to /etc/php.ini. I will try to this behavior further, and will update the post, just in case someone will have the same problem.
May be different php.ini used? One for php-cli and another for php-fpm?
change in
/etc/php5/fpm/php-fpm.conf
and
/etc/php5/cli/php.ini to be safe
and change where it has
upload_max_filesize = 2M
to whatever file size u want example
upload_max_filesize = 8M
then reload
/etc/init.d/php5-fpm restart
/etc/init.d/nginx reload
/etc/init.d/nginx restart

Categories