This article mainly introduces the solution to the file upload size limit problem of PHP and Nginx. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
Some websites for nginx PHP , the size of the uploaded file will be limited by many aspects. One is the limitation of nginx itself, which limits the size of the file uploaded by the client. The other is the default settings in multiple places in the php.ini file. Therefore, in order to solve the problem of uploading file size limit, many modifications must be made. A few places are listed below.
1. Modify the /usr/local/nginx/conf/nginx.conf file, find client_max_body_size and set the following value to the value you want to set. For example:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /home/www/htdocs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/htdocs$fastcgi_script_name; include fastcgi_params; client_max_body_size 35m; #客户端上传文件大小设为35M client_body_temp_path /home/www/nginx_temp; #设置临时目录 }
2. Modify php.ini
Check the following lines in php.ini:
upload_max_filesize = 8M post_max_size = 10M memory_limit = 20M max_execution_time=300 file_uploads = On 默认允许HTTP文件上传,此选项不能设置为OFF。 upload_tmp_dir =/tmp/www
When uploading a large file, you There will be a feeling of slow upload speed. When it exceeds a certain time, an error will be reported that the script execution exceeds 30 seconds. This is because the
max_execution_time configuration option in the php.ini configuration file is causing trouble, which indicates the maximum allowed for each script. Execution time (seconds), 0
means no limit. You can adjust the value of max_execution_time appropriately. Setting it to 0 is not recommended.
Related recommendations:
Comparison of the two deployment methods of PHP and Nginx (picture)
The above is the detailed content of Solution to PHP and Nginx file upload size limit problem. For more information, please follow other related articles on the PHP Chinese website!