Modify PHP configuration files to upload large files (apache/nginx)

Source: Internet
Author: User
Tags file upload ini php file php file upload

Windows + apache + php environment

In apache, the most common PHP file upload size limit is through php. as defined in the ini configuration file, you can modify the file size limit in PHP by modifying the values of the following three fields and re-enabling the server program (such as apache:

Upload_max_filesize = 8 M
Post_max_size = 10 M
Memory_limit = 20 M

The specific configuration is as follows:

Search in php. ini

The code is as follows: Copy code

Max_execution_time

The default value is 30 seconds.

The code is as follows: Copy code

Max_execution_time = 0

0 indicates no limit

The above modified the timeout time for script execution in php file uploading.

2. Modify post_max_size to set the maximum size allowed by POST data. This setting also affects php file upload.
The default post_max_size of php is 2 MB. If the size of POST data is larger than that of post_max_size $ _ POST and $ _ FILES superglobals, it is null.

Change to post_max_size.

The code is as follows: Copy code

Post_max_size = 150 M

3. Many people will change the second step. But the maximum size of php files uploaded is 8 MB.
Why? We need to change the parameter upload_max_filesize to indicate the maximum size of the uploaded file.
Find upload_max_filesize. The default value is 8 MB.

The code is as follows: Copy code

Upload_max_filesize = 100 M

In addition, it should be noted that in the PHP file upload, post_max_size is better than upload_max_filesize.

Modify the size of uploaded files in nginx + php


Previously, php was used to upload files. First, php was modified. ini settings, the server changed the environment a few days ago (using nginx + php), today suddenly found that a slightly larger file cannot be uploaded, tangled for a long time, finally, the error 413 caused by the client_max_body_size configuration option value of nginx is found. Now let's share the processing method.
Problem description:
Set upload_max_filesize to 50 MB in the php. ini configuration file.
The value of post_max_size is 100 MB.
However, if you upload a file that exceeds 10 MB, the system will return the uploaderror 413 error.
Server environment:
Centos5.7 32-bit
Nginx1.0.8
Php5.2.17

Solution:

1. If you have a file upload limit of 50 MB, first modify php. iniupload_max_filesize 50 M

The code is as follows: Copy code

Post_max_size 100 M

2. Modify the nginx configuration file:
The default value of this configuration option is 1 Mb, which can be increased to 8 MB to increase the file size limit. I have directly changed it to 100 here. You can set it as needed. (Reference: the client_max_body_size must be the same as the maximum values in upload_max_filesize and post_max_size in php. ini, or slightly larger. This will not cause errors due to inconsistent size of submitted data .)

The code is as follows: Copy code
Client_max_body_size 100 m;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.