简体   繁体   中英

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

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

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;
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM