wordpress - PHP The uploaded file exceeds the upload_max_filesize directive in php.ini
Get the solution ↓↓↓Before you mark this as duplicate, hear me out. I've tried all the suggestions I can find online. None works. I've restarted countless times. Detailed list of what I've tried below.
Here's my setup:
- Nginx 1.10
- PHP 7.0
- WordPress 4.7
- I'm on a VPS. I have access and control over EVERY single file!
Here's what I want to do:
- Increase the upload file size for my WordPress.
Why?
- Anytime I upload a file size bigger than 2 megabytes, I get this error:
The uploaded file exceeds the upload_max_filesize directive in php.ini.
That's all it tells me.
Here's what I have done:
a. So out of common sense, I go into
/etc/php/7.0/cli/php.ini
becausephp.ini -i
tells me the loaded configuration is from that file. In thephp.ini
file, I change theupload_max_filesize = 2M
toupload_max_filesize = 10M
b. I go ahead to restart, both Nginx (
sudo service nginx restart
), and PHP (sudo service php7.0-fpm restart
)
Above Doesn't work as 2 other approaches below: I still get:
The uploaded file exceeds the upload_max_filesize directive in php.ini.
- I create my own
user.ini
under/etc/php/7.0/cli/conf.d/
folder with contents,upload_max_filesize = 10M
I go ahead to do 1. b. Still same error
- They say something is called
error_reporting
. I go ahead to locate the error reporting in myphp.ini
file. I change from the first line below to the second:;error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_reporting = E_ALL
I do 1. b., Still doesn't work.
So what the #&)#(* is wrong with my setup and what again do I have to change somewhere else?
Is it even changeable? I've read and tried almost every single suggestion online, and it never works.
It has never been an issue for me, the 2 max upload, but I'm importing a wordpress xml file, which is just 3 Mb, and I've spent a couple of hours already trying to get this thing to work.
By default, can't the upload size be a bit higher. 2 Megabyte is even ridiculous for a site in recent years. At least 5 is much better.
Any help is appreciated!
Answer
Solution:
You're looking at the php.ini file for the CLI, you need to look at the PHP ini file for the web server you're running. Within the WP directory, create a temporary php file, and have it contain<?php phpinfo();
navigate to that file in the browser and find the php.ini file you actually need to change, then make the change as required.
NOTE: Remove this file once you're done with your checks, having this information visible to the public is a security risk
Answer
Solution:
Case 1 : Add php.ini in wp-admin folder
Navigate to wp-admin folder. Scroll down to see if you have a php.ini file in there.If you didn’t add one at some point.
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
Case 2 : Add code to .htaccess
Open or create the .htaccess file in the root folder and add the following code:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
Answer
Solution:
Initially, I tried JezEmery 's answer, but for me the solution came when typed on terminal
locate php.ini
and I took among else as printout
/usr/lib/php/7.0/php.ini-development
/usr/lib/php/7.0/php.ini-production
/usr/lib/php/7.0/php.ini-production.cli
/usr/lib/php/7.1/php.ini-development
/usr/lib/php/7.1/php.ini-production
/usr/lib/php/7.1/php.ini-production.cli
then change the php7.1 files, as my apache used version 7.1 of php, and last, I restarted apache via
systemctl restart apache2
Answer
Solution:
Simply Add these lines of codes in C:/xampp/php.ini
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
After restart the xampp control and check the panel it'll increase the file size
Answer
Solution:
If you're using php-fpm but not Apache, sometimes after doing all the above, you need to restart thephp7.4-fpm
service. It may be named differently depending on your PHP version.
sudo systemctl restart php7.4-fpm
Answer
Solution:
Add below code into theme's function.php file
@ini_set( 'upload_max_size' , '64M' );
@ini_set( 'post_max_size', '64M');
@ini_set( 'max_execution_time', '300' );
OR
Create php.ini into root folder with below lines:
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
Add code into .htaccess file:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
Answer
Solution:
What doesphp -i | grep 'upload_max_filesize'
give you? The10M
you set or a different value. If it's giving you the latter then you're editing the wrong php.ini file. You can usephp --ini
to figure which config file is loaded
Answer
Solution:
In cwp (control web panel) if you use php-fpm, you have to modifyphp.ini
in this directory:/opt/alt
. Or you can do it from control panel: Dashboard>PHP Settings>PHP-FPM Selector> PHP-FPM x.x >Edit php.ini an after changeupload_max_filesize
, reload PHP using related (yellow) button in the left.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: undefined array key php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.