PHPMyAdmin – 資料無法匯入

測試環境 CentOS 8 64bits + Apache + php-fpm (與 CentOS 7 不同,請參考 – http://benjr.tw/101989 )

  • CentOS 8 + PHP Version 7.2.11
    Server API 使用 FPM/FastCGI
  • CentOS 7 + PHP Version 5.4.16
    Server API 使用 Apache 2.0 Handler

我們可以透過 MyPHPAdmin 的匯入 ( Import )功能,把資料匯入資料庫,但當資料大於 2M 時會出現以下的資訊.

沒有接收到要匯入的資料。 可能是檔案名稱沒有被送出或是檔案大小超出 PHP 限制。 請參考 FAQ 1.16。
No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration. See FAQ 1.16.

主要是被 PHP 上傳檔案 2M 的上限所限制住,我們可以透過 PHP 函數 phpinfo() 來看一下目前關於上傳檔案限制的設定.
可以使用編輯器來鍵入 PHP 程式碼,內容如下 (檔案需儲存在 /var/www/html – Apache 預設的目錄),或是透過 echo 直接產生.

[root@benjr ~]# echo "<?php phpinfo() ?>" > /var/www/html/phpinfo.php

開啟你的網頁連上你 http://Host_IP/phpinfo.php ,如果 PHP 一切運作正常,可以找到跟上傳檔案大小相關的設定 post_max_size 與 upload_max_filesize.

  1. post_max_size – Local / Master Value 預設為 8M.
    post_max_size 是針對請求的整個主體的限制 (使用者可能一次上傳多個檔案)
  2. upload_max_filesize – Local / Master Value 預設為 2M.
    upload_max_filesize 是針對單個檔案大小的限制。

設定值有分為 Master Value (PHP.ini 設定檔) 以及 Local value (當前目錄中的設定檔,會覆蓋過 Master Value 的值),可以透過下面幾種方式來做.

  1. 修改 php.ini
    [root@localhost ~]# vi /etc/php.ini
    ; Maximum execution time of each script, in seconds
    ; http://php.net/max-execution-time
    ; Note: This directive is hardcoded to 0 for the CLI SAPI
    max_execution_time = 30
    
    ; Maximum amount of time each script may spend parsing request data. It's a good
    ; idea to limit this time on productions servers in order to eliminate unexpectedly
    ; long running scripts.
    ; Note: This directive is hardcoded to -1 for the CLI SAPI
    ; Default Value: -1 (Unlimited)
    ; Development Value: 60 (60 seconds)
    ; Production Value: 60 (60 seconds)
    ; http://php.net/max-input-time
    max_input_time = 60
    
    ; 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 = 20M
    
    ; Maximum allowed size for uploaded files.
    ; http://php.net/upload-max-filesize
    upload_max_filesize = 20M
    
    ; Maximum number of files that can be uploaded via a single request
    max_file_uploads = 20
    

    當檔案比較大時所需上傳時間也需要修改,下面這兩個參數可以做調整.

    1. max_input_time integer
      This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins. 預設值為 60秒.
    2. max_execution_time integer
      This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. 預設值為 30秒.
    [root@localhost ~]# systemctl restart php-fpm
    

    再次開啟你的網頁連上你 http://Host_IP/phpinfo.php ,檢視一下 post_max_size 與 upload_max_filesize 的 Local Value 設定都修改了.

  2. 修改 .user.ini
    CentOS 8 採用 Apache + php-fpm 的方式.

    無法使用 /var/www/html/.htaccess 設定 php_value upload_max_filesize 20M 的方式來做,會出現以下的錯誤訊息.
    網頁:

    Internal Server Error
    
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    
    Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.
    
    More information about this error may be available in the server error log.
    

    error_log:

    [root@localhost ~]# cat /var/log/httpd/error_log
    /var/www/html/.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
    

    需要改用 .user.ini 設定檔(設定方式同 php.ini).

    [root@localhost ~]# vi /var/www/html/.user.ini
    upload_max_filesize = 1024M
    post_max_size = 1024M
    max_execution_time = 300
    max_input_time = 300
    

    這個方式不需要重啟服務,只需再次開啟你的網頁連上你 http://Host_IP/phpinfo.php ,檢視一下 post_max_size 與 upload_max_filesize 的 Local Value 設定都修改了.

沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料