Database Uploads for WordPress with PHP: Difference between revisions

mNo edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:


=== Solution? ===
=== Solution? ===
Change some settings in /etc/php.ini (or other locations like /opt/remi, if using REMI for multiple PHP versions.
Change settings in /etc/php.ini (or other locations like /opt/remi, if using REMI for multiple PHP versions.


=== php.ini Settings ===
== php.ini ==
Large WordPress database imports through phpMyAdmin may fail when PHP upload limits, post limits, memory limits, or execution timers are too low.
Below are the main settings to modify. Jack 'em up higher if you have the RAM and / or need to import some really big stuff.<syntaxhighlight lang="ini">
 
== Common PHP Settings ==
 
Recommended example for a large import:
 
<syntaxhighlight lang="ini">
upload_max_filesize = 512M
upload_max_filesize = 512M
post_max_size = 600M
post_max_size = 600M
Line 19: Line 13:
</syntaxhighlight>
</syntaxhighlight>


{| class="wikitable"
=== Directive Definitions ===
; <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.
 
== Settings can also be done in phpMyAdmin ==
 
If it isn't desirable to modify system wide php.ini settings, just do it for phpMyAdmin.  Location of where the config file is varies depending on the 'flavor' of Linux being used.


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


<code>$cfg['UploadDir']</code> lets an SQL file be copied to the server first, then selected from phpMyAdmin, avoiding browser upload limits.
=== More Definitions ===
 
; <code>$cfg['ExecTimeLimit']</code>
== Per-Site Configuration ==
: phpMyAdmin execution time limit.
 
Depending on the PHP handler:


<syntaxhighlight lang="apache">
; <code>$cfg['MemoryLimit']</code>
# Apache module / mod_php only
: phpMyAdmin memory limit override.
php_value upload_max_filesize 512M
php_value post_max_size 600M
php_value memory_limit 768M
php_value max_execution_time 600
php_value max_input_time 600
</syntaxhighlight>


For CGI/FastCGI or PHP-FPM, use a per-directory <code>.user.ini</code> instead:
; <code>$cfg['UploadDir']</code>
: Allows SQL files to be copied to a server-side upload directory and selected from phpMyAdmin, avoiding browser upload limits.


<syntaxhighlight lang="ini">
== .htaccess too ==
Settings can be done on a per website basis too.<syntaxhighlight lang="ini">
upload_max_filesize = 512M
upload_max_filesize = 512M
post_max_size = 600M
post_max_size = 600M
Line 69: Line 58:
</syntaxhighlight>
</syntaxhighlight>


== Notes ==
== Remember ==


* Restart or reload the web server / PHP-FPM after changing global PHP configuration.
* Don't forget to restart PHP-FPM or other PHP related daemons / services if editing php.ini, as those settings won't apply until that's done
* Browser-based phpMyAdmin imports are convenient but not ideal for very large databases.
* Restarting httpd or apache2, etc, won't cut it.
* For very large SQL files, command-line MySQL import is usually more reliable.


== 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]