413 Request Entity Too Large - File Upload Issue - php

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

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

Errors 504 and 413 in fresh installation on NGINX server

I have set up my first nginx server and in PhpMyAdmin i am getting the following errors:
Error 413 - Request Entity Too Large
Error 504 - Gateway Timeout Reloaded
I used the following line and install the nginx and php files.
sudo apt-get install nginx php7.3 php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-mbstring php7.3-cli
php7.3-common php7.3-curl php7.3-zip php7.3-xml php7.3-json php7.3-opcache php7.3-readline
I might not needed all, as my web application is a simple CRUD style base on PDO, MySQL.
I am reading in the site that i have to change-edit some congif but i can make it work.
Do i have to change them in NGINX, PHP, PHP-FPM?
What i must add/edit in here, NGINX:
/etc/nginx/sites-enabled/default
or here:
/etc/nginx/nginx.conf
client_max_body_size = 0; in the server section
What i must add/edit in here, PHP:
/etc/php/7.3/cli/php.ini
max_execution_time = 600
upload_max_filesize = 15M
post_max_size = 15M
What i must add/edit in here, PHP-FPM:
/etc/php/7.3/fpm/php.ini
request_terminate_timeout = 600
upload_max_filesize = 15M
post_max_size = 15M
Do i need to make changes to another file, like ExecTimeLimit to 0 in PhpMyAdmin(where it is located) or any other?
I have found this for the time....
I followed this steps at it seems to work fine now.
### PhpMyAdmin - Error 413(Request Entity Too Large)
### PhpMyAdmin - Error 504(Gateway Timeout Reloaded)
### Edit "Nginx" Config File:
sudo nano /etc/nginx/nginx.conf
### Add The Following Lines, Inside Http{} On Top:
# Fix Error 413: Request Entity Too Large
client_max_body_size 20M;
### Edit "Nginx/Sites-Enabled" Config File:
sudo nano /etc/nginx/sites-enabled/default
### Add The Following Lines, Inside Server{} On Top.
# Fix Error 413: Request Entity Too Large
client_max_body_size 20M;
### Edit The Following Lines, Inside Server{location ~ \.php$ {}}.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# Fix TimeOut Error <=== Add This One ===>
fastcgi_read_timeout 600; <=== Add This One ===>
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
### Edit "PHP.ini" File:
sudo nano /etc/php/7.3/cli/php.ini
### Find Lines And Edit:
max_execution_time = 600
upload_max_filesize = 20M
post_max_size = 20M
### Edit "PHP-FPM" File:
sudo nano /etc/php/7.3/fpm/php.ini
### Find Lines And Edit:
max_execution_time = 600
upload_max_filesize = 20M
post_max_size = 20M
### Reload "Nginx" And "PHP7.3-FPM"(or Restart):
sudo service php7.3-fpm reload
sudo service nginx reload
Must of my problem solved but if i tried in PHPMyAdmin/SQL page, to insert 30K rows, i am getting error.
According to error.log
2020/12/13 20:17:01 [error] 3920#3920: *262 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 10.0.19.67, $
2020/12/13 20:33:19 [notice] 13839#13839: signal process started
2020/12/13 20:38:45 [error] 13840#13840: *264 FastCGI sent in stderr: "PHP message: PHP Fatal error: Maximum execution time of 300 seconds exceeded in /usr$
I am missing something?

stream_socket_sendto(): Connection refused

I'm using Laravel. When I dd($request->all()) that the data inside it involves file and some other data. it returns the error
[2019-02-22 19:40:24] local.ERROR: stream_socket_sendto(): Connection
refused {"exception":"[object] (RuntimeException(code: 0):
stream_socket_sendto(): Connection refused at
/vendor/symfony/var-dumper/Server/Connection.php:63
So I got that there might be a php-fpm bad configuration. Because I'm using Apache 2.4.6 so I can't use Listen 127.0.0.1:9000 as I know it is only for Apache 2.4.10 and later. So I used listen = /run/php-fpm/www.sock. But this one can't have any port. BTW the www.sock file size is 0 and the its owner is root.
Is the error that Laravel/PHP returns, related to php-fpm configuration?
If yes how can I overcome this issue?
Most time this is not a laravel issue but php file upload size issue.
so what you need to do is to increase the upload size in php.ini file. on your terminal you can do this
sudo nano /etc/php/7.2/apache2/php.ini
then update this lines
memory_limit = 1G
upload_max_filesize = 1G
post_max_size = 1G
also update this file
sudo nano /etc/php/7.2/cli/php.ini
memory_limit = 1G
upload_max_filesize = 1G
post_max_size = 1G
Don't forget to restart apache
service apache2 restart
and laravel php artisan serve

/etc/php/7.0/fpm/zz_overrides.ini isn't effective (isn't counted) after server restart

In Ubuntu 16.04 with Nginx (LEMP) I created the file /etc/php/7.0/fpm/zz_overrides.ini.
The file contains only this code:
[PHP]
post_max_size = 2000M
upload_max_filesize = 2000M
max_execution_time = 3000
cgi.fix_pathinfo=0
After creating the file I saved it and restarted Nginx and PHP-FPM:
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
And yet, I don't see the effect. For example, I can still upload data up until 2 megabytes instead 2000 megabytes, see:
My question
Why is the zz_overrides.ini file isn't effective?
Create a php file with the following content:
<?php
phpinfo();
?>
There you can see all current settings.
In the first section you have "Additional .ini files parsed".
So you can see which files are loaded.
Also "Scan this dir for additional .ini files" shows you which additional folders are scanned for config files.
What I had to do is to enable my additional php.ini file
I did so by creating a softlink (symlink) to it, in conf.d directory:
ln -s /etc/php/7.0/fpm/zz_overrides.ini 20-zz-overrides.ini
Then indeed I saw the desired change:
Version-agnostic variant
A version-agnostic (version independent) variant of this command is this:
ln -s /etc/php/*/fpm/zz_overrides.ini 20-zz-overrides.ini

Max filesize not taking effect from php.ini

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

Categories