Cannot upload files bigger than 10MB - php

I'm trying to let user upload up to 30MB max but the server hangs not even produce an error. Not even error in browser network bar in inspection. I did changes below after reading whole lot of info on Internet but no luck so far. Anyone knows what else I can do?
Thanks in advance
.htaccess:
<IfModule mod_php5.c>
php_value post_max_size 40M
php_value upload_max_filesize 350M
php_value max_execution_time 1200
php_value max_input_time 1200
</IfModule>
/etc/php5/{cli,fpm}/php.ini
post_max_size 40M
upload_max_filesize 35M
max_execution_time 1200
max_input_time 1200
RESTART:
sudo service php5-fpm restart
sudo service apache2 restart

For others who could face this issue, there could be also Apache's ModSecurity setting SecRequestBodyLimit (in case of using Apache) and in system log you'll get the following error:
ModSecurity: Request body (Content-Length) is larger than the configured limit (10485760)

One thing to check is the maximum post size set in the PHP Suhosin security patch. This complements the settings in your php.ini and might cause the issues that you're seeing. A similar question here: https://serverfault.com/questions/486134/php-cant-increase-maximum-upload-limit
Let me know if it worked.

Related

Increasing Execution Time for php

Update: This is not a dublicate question! I researched and tried many options/answers, but still, the web page is not allowing users to upload a file after exactly 20 seconds.
Update: I tried to switch from fast-cgi to php-fpm, but it did not work for me either. What else should I change in order to overcome timeout of 20 seconds?
When I am uploading large files via web browser, exactly after 20 seconds, it stops uploading. Specifically, approximately 40% of 100 MB file uploads fine during 20 seconds; I see the percentage of the upload under the Chrome browser. Then, the value of the percentage stops after 20 seconds and shows ERR_CONNECTION_RESET error. I checked logs, but there is nothing regarding the issue.
My php.ini configuration as follows:
max_execution_time 300000
max_input_time 300000
upload_max_filesize 500M
post_max_size 500M
memory_limit 1024M
max_file_uploads 30
Timeout 8000 (in apache2.conf)
LimitRequestBody 0 (in htaccess)
What else should I change in order to increase an execution time? Obviously, there is some config that does not allow to upload a file after 20 seconds. My assumption is that there is something in Apache Configuration that must be tuned.
<IfModule mod_php5.c>
php_value post_max_size 100M
php_value upload_max_filesize 100M
php_value memory_limit 100M
php_value max_execution_time 300000
php_value max_input_time 300000
php_value session.gc_maxlifetime 1200
</IfModule>
insert this in .htaccess file. try whether its working or not
you should change max_input_time,upload_max_file_size and post_data_limit in php.ini file. It should work.
change values
max_execution_time 25000
max_input_time 25000
memory_limit 500M
display_errors On ;to see where is problem
post_max_size 500M
upload_max_filesize 500M
and restart your apache or nginx tu load changes
in ubuntu you can use this command to restart apache sudo service apache2 restart

PostTooLargeException in Laravel

I am getting the post too large exception when I try to upload files which are more than 2 MB in size and I've already tried everything like increasing the post_max_size and max_upload_size in php.ini file but I am still getting the same error. When I comment the handler function in validatepostsize.php file it shows token mismatch error:
I think you can check the following parameters in your php.ini file like:
upload_max_filesize = 40m
post_max_size = 50m
After restart your server like (apache)
Hope this work for you!
First, check your PHP version.
php -v
The command below will print the path to the php.ini file that your server is using.
php -i | grep php.ini
Next.
sudo nano /etc/php/7.4/cli/php.ini
The values of post_max_size, upload_max_filesize and memory_limit by default have the value of 8M, 2M, and 128M respectively.
Search for those variables and change their values, whilst ensuring that the sizes follow the same ratio as the default values.
See example below:
post_max_size = 2G
upload_max_filesize = 1G
memory_limit = 3G
For "heavy-loaded sites", it is useful to have FPM installed and running.
sudo apt install php7.4-fpm -y
sudo service php7.4-fpm start
Finally, restart your web server.
sudo service apache2 restart
One of the issues is that the Laravel PHP artisan serve local development server uses the php.ini under PHP/CLI instead of under PHP/apache2
So if you are having this issue while developing with PHP artisan serve, go and fetch the php.ini that's under the /etc/php[version]/cli folder.
Its not the best solution just to change parameters in php.ini and then restart apache:
upload_max_filesize = 128M
post_max_size = 128m
//or whatever value you think is right
Restart apache like this:
sudo service apache2 restart
The best way as for me is to catch PostTooLargeException using Error Handling of laravel: Error Handling
For a detailed answer how to catch PostTooLargeException using Error Handling you can see my answer in this thread: thread with full answer. I struggled like 2 days before I fully figured how to achieve that.
Happy coding!
Actually I am looking for the same answer for the same issue.
I have found out that the issue can be resolve with an edit of .htaccess file.
Add the below code in the file.
php_value upload_max_filesize 50M
php_value post_max_size 50M
This above two line will resolve the issue but if you are adding this much size then the line below give will save you from future issue. of like execution time expire and
all.
php_value max_input_time 120
php_value max_execution_time 120
For a more accurate validation, I recommend setting the values in bytes, because 50 MB is 52428800B, which actually 52 MB, not 5000000B.
.htaccess example:
php_value upload_max_filesize 50000000B // 50M
php_value post_max_size 50000000B // 50M

Adding max_input_vars 3000 to my .htaccess file and php.ini not working

I've done some searching and seems everything I've read and tried with adding max_input_vars 3000 to my .htaccess and php.ini is not working. I've reached the limit on custom fields and can't get the max increased. I added these lines and restarted apache but nothing helps.
Here is what I added to .htaccess:
php_value max_input_vars 3000
php_value suhosin.get.max_vars 3000
php_value suhosin.post.max_vars 3000
php_value suhosin.request.max_vars 3000
And here is my php.ini:
max_input_vars 3000
suhosin.get.max_vars 3000
suhosin.post.max_vars 3000
suhosin.request.max_vars 3000
Repost from:
[https://stackoverflow.com/a/29312220/3827361][1]
I had the same issue, and I fixed it by setting max_input_vars value in this php.ini: /etc/php5/apache2/php.ini
even though php_info() reported a different php.ini used (/etc/php5/cli/php.ini). BTW, before I stumbled upon the solution, I also tried setting up the value in .htaccess (in the web page root directory), with no effect.
This looks like a possible bug in PHP 5.5. In any case, I suggest locating all php.ini files on your server ("locate php.ini") and setting max_input_vars in all of them (or the first one that works, eh). Don't forget to restart Apache so this takes effect (sudo /etc/init.d/apache2 restart)
BTW, my PHP Version is 5.5.9-1ubuntu4.5, installed on Ubuntu 14.04.
You can change your max_input_vars value to 2000 or any value that you want in htaccess by adding this for PHP 7.*:
<IfModule mod_php7.c>
php_value max_input_vars 2000
</IfModule>
And for PHP 8.* use this:
<IfModule mod_php8.c>
php_value max_input_vars 2000
</IfModule>

php upload and internal server error

i am using an html form with php to upload data to mysql.
the form is working properly when i am using it on my laptop (wamp) but when i uploaded the site on my dedicated server (ispconfig) get this error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
i tried changing the values of the php.ini in
post_max_size 64M
upload_max_filesize 64M
max_input_time 3000
max_execution_time 3000
and the ones in the apache also in
memory_limit 96M
post_max_size 64M
upload_max_filesize 64M
but i still cant upload.
thank you for reading this.
You need to increase FcgidMaxRequestLen in httpd.conf file
use something like
FcgidMaxRequestLen 67108864
From FcgidMaxRequestLen Directive
Warning
Before 2.3.6, this defaulted to 1GB. Most users of earlier versions
should use this directive to set a more reasonable limit.
The accepted answer is correct. To be more specific, you need to add the code in httpd.conf file :
# Work around annoying fcgid limitations
<IfModule mod_fcgid.c>
# 20MB should be enough
MaxRequestLen 20000000
</IfModule>
You may check the full article here :
http://pivica.me/blog/500-internal-server-error-while-uploading-files-bigger-then-100kb-modfcgid-problem
Note that a syntax error in a php/ajax processing script could report as an "internal server error".
For example, I was using Ravishanker Kusuma's jQuery Upload File plugin and was getting this message.
Turns out it was just a missing ) in an (unused) function inside my code in the PHP processor file specified by the AJAX script. When a file was uploaded, this script would be called, the script would break inside the unused function, and this is the error it would report.
FWIW
None of the solutions above worked for me.
For CentOS users with Plesk Pannel follow the next steps
Change this value in the template
# grep -ir FcgidMaxRequestLen /usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php
FcgidMaxRequestLen 16777216
# sed -i 's/FcgidMaxRequestLen 16777216/FcgidMaxRequestLen 1073741824/g' /usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php
# grep -ir FcgidMaxRequestLen /usr/local/psa/admin/conf/templates/default/domain/domainVirtualHost.php
FcgidMaxRequestLen 1073741824
Rebuild the virtualhost configurations.
# /usr/local/psa/admin/bin/httpdmng --reconfigure-all
# /usr/local/psa/admin/bin/httpdmng --reconfigure-server
https://support.plesk.com/hc/en-us/articles/213955145-Unable-to-upload-large-files-via-PHP-HTTP-request-length-exceeds-MaxRequestLen

post_max_size resets to default

Scenario: Installed an adult tubescript for a pornsite. Keeps having problems with file upload over 8MB
I figured it has something to do with php.ini, so I checked and changed it to
post_max_size = 200M
upload_max_size = 200M
On .htaccess of the script, there is these two lines:
php_value upload_max_filesize 1000M
php_value post_max_size 1000M
but when I check using phpinfo(), post_max_size is still 8M and I still can't upload anything over 8MB. I've been working on this for 3 days now and I really can't figure it out.
What could possibly be causing this?
Dedicated Server: FreeBSD 8.2, Nginx 1.0.6, PHP 5.2
I've learned that Nginx needs a php feeder/loader: fastcgi
In my case it's spawn-fcgi
here's how I fixed it
/usr/local/etc/rc.d/spawn-fcgi restart
/usr/local/etc/rc.d/nginx restart
Thanks for the replies.
Credits to DarkZenith for the pointers.

Categories