Database Uploads for WordPress with PHP: Difference between revisions

mNo edit summary
mNo edit summary
Line 4: Line 4:
Change some settings in /etc/php.ini (or other locations like /opt/remi, if using REMI for multiple PHP versions.
Change some settings in /etc/php.ini (or other locations like /opt/remi, if using REMI for multiple PHP versions.


=== php.ini Settings ===
= PHP Settings for Large phpMyAdmin Imports =
Large WordPress database imports through phpMyAdmin may fail when PHP upload limits, post limits, memory limits, or execution timers are too low.


== Common PHP Settings ==
Large WordPress database imports through phpMyAdmin can fail when PHP upload limits, POST limits, memory limits, or execution timers are too low.


Recommended example for a large import:
== Main php.ini Settings ==


<syntaxhighlight lang="ini">
<syntaxhighlight lang="ini">
Line 19: Line 18:
</syntaxhighlight>
</syntaxhighlight>


{| class="wikitable"
; <code>upload_max_filesize</code>
: Maximum size of an uploaded SQL file.


| ! Setting !! Purpose            |  |                                                                                            |
; <code>post_max_size</code>
| -------------------------------- | - | ------------------------------------------------------------------------------------------ |
: Maximum total HTTP POST request size. Set this larger than <code>upload_max_filesize</code>.
| <code>upload_max_filesize</code> |  | Maximum uploaded SQL file size.                                                            |
| -                                |  |                                                                                            |
| <code>post_max_size</code>      |  | Maximum total HTTP POST body size. Should be larger than <code>upload_max_filesize</code>. |
| -                                |  |                                                                                            |
| <code>memory_limit</code>        |  | PHP memory ceiling. Should usually be larger than <code>post_max_size</code>.              |
| -                                |  |                                                                                            |
| <code>max_execution_time</code>  |  | Maximum PHP script run time, in seconds.                                                  |
| -                                |  |                                                                                            |
| <code>max_input_time</code>      |  | Maximum time PHP may spend receiving input, including uploads.                            |
| }                                |  |                                                                                            |


== phpMyAdmin-Specific Settings ==
; <code>memory_limit</code>
: Maximum memory PHP may use. For large imports, set this larger than <code>post_max_size</code>.


In <code>config.inc.php</code>:
; <code>max_execution_time</code>
: Maximum script execution time, in seconds.
 
; <code>max_input_time</code>
: Maximum time PHP may spend receiving input, including uploads.
 
== phpMyAdmin Settings ==
 
These go in phpMyAdmin's <code>config.inc.php</code> file.


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 44: Line 43:
</syntaxhighlight>
</syntaxhighlight>


<code>$cfg['UploadDir']</code> lets an SQL file be copied to the server first, then selected from phpMyAdmin, avoiding browser upload limits.
; <code>$cfg['ExecTimeLimit']</code>
: phpMyAdmin execution time limit.
 
; <code>$cfg['MemoryLimit']</code>
: phpMyAdmin memory limit override.
 
; <code>$cfg['UploadDir']</code>
: Allows SQL files to be copied to a server-side upload directory and selected from phpMyAdmin, avoiding browser upload limits.


== Per-Site Configuration ==
== Per-Site Configuration ==


Depending on the PHP handler:
If PHP runs as an Apache module, settings may be placed in <code>.htaccess</code>:


<syntaxhighlight lang="apache">
<syntaxhighlight lang="apache">
# Apache module / mod_php only
php_value upload_max_filesize 512M
php_value upload_max_filesize 512M
php_value post_max_size 600M
php_value post_max_size 600M
Line 59: Line 64:
</syntaxhighlight>
</syntaxhighlight>


For CGI/FastCGI or PHP-FPM, use a per-directory <code>.user.ini</code> instead:
If PHP runs through CGI, FastCGI, or PHP-FPM, use <code>.user.ini</code> instead:


<syntaxhighlight lang="ini">
<syntaxhighlight lang="ini">
Line 71: Line 76:
== Notes ==
== Notes ==


* Restart or reload the web server / PHP-FPM after changing global PHP configuration.
* Reload or restart the web server or PHP-FPM service after global PHP changes.
* Browser-based phpMyAdmin imports are convenient but not ideal for very large databases.
* For very large databases, command-line import with <code>mysql</code> or <code>mariadb</code> is usually more reliable than browser upload through phpMyAdmin.
* For very large SQL files, command-line MySQL import is usually more reliable.
* Web server limits may also apply, such as Apache request limits or Nginx <code>client_max_body_size</code>.


== External References ==
== References ==


* [https://www.php.net/manual/en/ini.core.php PHP Manual: Core php.ini directives]
* [https://www.php.net/manual/en/ini.core.php PHP Manual: Core php.ini directives]
* [https://www.php.net/manual/en/features.file-upload.common-pitfalls.php PHP Manual: File upload common pitfalls]
* [https://www.php.net/manual/en/features.file-upload.common-pitfalls.php PHP Manual: File upload common pitfalls]
* [https://www.php.net/manual/en/configuration.changes.php PHP Manual: How to change configuration settings]
* [https://www.php.net/manual/en/configuration.changes.php PHP Manual: Changing configuration settings]
* [https://www.php.net/manual/en/configuration.file.per-user.php PHP Manual: .user.ini files]
* [https://www.php.net/manual/en/configuration.file.per-user.php PHP Manual: .user.ini files]
* [https://docs.phpmyadmin.net/en/latest/config.html phpMyAdmin Documentation: Configuration]
* [https://docs.phpmyadmin.net/en/latest/config.html phpMyAdmin Documentation: Configuration]
* [https://docs.phpmyadmin.net/en/master/faq.html phpMyAdmin FAQ: Cannot upload big dump files]
* [https://docs.phpmyadmin.net/en/latest/faq.html#i-cannot-upload-big-dump-files-memory-http-or-timeout-problems phpMyAdmin FAQ: Cannot upload big dump files]