phpMyAdmin + Nginx 修改匯入 .SQL 檔案大小限制|php.ini|client_max_body_size|upload_max_filesize|post_max_size|伊恩踩坑筆記

413 Request Entity Too Large
You probably tried to upload too large file. Please refer to documentation for ways to workaround this limit.

很久沒有用 phpMyAdmin 了,正要重溫的時候發現匯入不了 .sql 檔案,原因是文件太大了,匯入大小的限制預設是 2 MB

出現了 413 Request Entity Too LargeYou probably tried to upload too large file. Please refer to documentation for ways to workaround this limit. 的錯誤訊息

先前往你的 server 的 php 版本,找到 php.ini

$ nano /etc/php/7.4/fpm/php.ini

搜尋 upload_max_filesizepost_max_size 把它設成大一點,我這邊設定的是 100G

...
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100G
...
...
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 100G
...

完成後重啟

$ /etc/init.d/php7.4-fpm restart

php 7.4
Ubuntu 20.04.2 LTS

再來是前往 Nginx 找到 nginx.conf 設定檔

$ nano /etc/nginx/nginx.conf

server, location, 或 http 的區塊中加入 client_max_body_size 參數

server {
client_max_body_size 100G;
}

完成後重啟

$ nginx -s reload

php.ininginx 都要設定才行唷~

ING Design 応設計
https://www.theingdesign.com/

--

--

Ian aka BerLin / 伊恩踩坑筆記

專門寫一些自己曾經踩過的坑,希望你沒踩過 / Web & BackEnd Developer • 台北 • theingdesign.com • IG: @ianakaberlin