Examples

See following configuration snippets for typical setups of phpMyAdmin.

Basic example

Example configuration file, which can be copied to config.inc.php to get some core configuration layout; it is distributed with phpMyAdmin as config.sample.inc.php. Please note that it does not contain all configuration options, only the most frequently used ones.

  1. <?php
  2. /**
  3. * phpMyAdmin sample configuration, you can use it as base for
  4. * manual configuration. For easier setup you can use setup/
  5. *
  6. * All directives are explained in documentation in the doc/ folder
  7. * or at <https://docs.phpmyadmin.net/>.
  8. */
  9. declare(strict_types=1);
  10. /**
  11. * This is needed for cookie based authentication to encrypt password in
  12. * cookie. Needs to be 32 chars long.
  13. */
  14. $cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
  15. /**
  16. * Servers configuration
  17. */
  18. $i = 0;
  19. /**
  20. * First server
  21. */
  22. $i++;
  23. /* Authentication type */
  24. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  25. /* Server parameters */
  26. $cfg['Servers'][$i]['host'] = 'localhost';
  27. $cfg['Servers'][$i]['compress'] = false;
  28. $cfg['Servers'][$i]['AllowNoPassword'] = false;
  29. /**
  30. * phpMyAdmin configuration storage settings.
  31. */
  32. /* User used to manipulate with storage */
  33. // $cfg['Servers'][$i]['controlhost'] = '';
  34. // $cfg['Servers'][$i]['controlport'] = '';
  35. // $cfg['Servers'][$i]['controluser'] = 'pma';
  36. // $cfg['Servers'][$i]['controlpass'] = 'pmapass';
  37. /* Storage database and tables */
  38. // $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
  39. // $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
  40. // $cfg['Servers'][$i]['relation'] = 'pma__relation';
  41. // $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
  42. // $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
  43. // $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
  44. // $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
  45. // $cfg['Servers'][$i]['history'] = 'pma__history';
  46. // $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
  47. // $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
  48. // $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
  49. // $cfg['Servers'][$i]['recent'] = 'pma__recent';
  50. // $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
  51. // $cfg['Servers'][$i]['users'] = 'pma__users';
  52. // $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
  53. // $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
  54. // $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
  55. // $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
  56. // $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
  57. // $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
  58. /**
  59. * End of servers configuration
  60. */
  61. /**
  62. * Directories for saving/loading files from server
  63. */
  64. $cfg['UploadDir'] = '';
  65. $cfg['SaveDir'] = '';
  66. /**
  67. * Whether to display icons or text or both icons and text in table row
  68. * action segment. Value can be either of 'icons', 'text' or 'both'.
  69. * default = 'both'
  70. */
  71. //$cfg['RowActionType'] = 'icons';
  72. /**
  73. * Defines whether a user should be displayed a "show all (records)"
  74. * button in browse mode or not.
  75. * default = false
  76. */
  77. //$cfg['ShowAll'] = true;
  78. /**
  79. * Number of rows displayed when browsing a result set. If the result
  80. * set contains more rows, "Previous" and "Next".
  81. * Possible values: 25, 50, 100, 250, 500
  82. * default = 25
  83. */
  84. //$cfg['MaxRows'] = 50;
  85. /**
  86. * Disallow editing of binary fields
  87. * valid values are:
  88. * false allow editing
  89. * 'blob' allow editing except for BLOB fields
  90. * 'noblob' disallow editing except for BLOB fields
  91. * 'all' disallow editing
  92. * default = 'blob'
  93. */
  94. //$cfg['ProtectBinary'] = false;
  95. /**
  96. * Default language to use, if not browser-defined or user-defined
  97. * (you find all languages in the locale folder)
  98. * uncomment the desired line:
  99. * default = 'en'
  100. */
  101. //$cfg['DefaultLang'] = 'en';
  102. //$cfg['DefaultLang'] = 'de';
  103. /**
  104. * How many columns should be used for table display of a database?
  105. * (a value larger than 1 results in some information being hidden)
  106. * default = 1
  107. */
  108. //$cfg['PropertiesNumColumns'] = 2;
  109. /**
  110. * Set to true if you want DB-based query history.If false, this utilizes
  111. * JS-routines to display query history (lost by window close)
  112. *
  113. * This requires configuration storage enabled, see above.
  114. * default = false
  115. */
  116. //$cfg['QueryHistoryDB'] = true;
  117. /**
  118. * When using DB-based query history, how many entries should be kept?
  119. * default = 25
  120. */
  121. //$cfg['QueryHistoryMax'] = 100;
  122. /**
  123. * Whether or not to query the user before sending the error report to
  124. * the phpMyAdmin team when a JavaScript error occurs
  125. *
  126. * Available options
  127. * ('ask' | 'always' | 'never')
  128. * default = 'ask'
  129. */
  130. //$cfg['SendErrorReports'] = 'always';
  131. /**
  132. * You can find more configuration options in the documentation
  133. * in the doc/ folder or at <https://docs.phpmyadmin.net/>.
  134. */

警告

Don’t use the controluser ‘pma’ if it does not yet exist and don’t use ‘pmapass’ as password.

Example for signon authentication

This example uses examples/signon.php to demonstrate usage of Signon 认证方式:

  1. <?php
  2. $i = 0;
  3. $i++;
  4. $cfg['Servers'][$i]['auth_type'] = 'signon';
  5. $cfg['Servers'][$i]['SignonSession'] = 'SignonSession';
  6. $cfg['Servers'][$i]['SignonURL'] = 'examples/signon.php';

Example for IP address limited autologin

If you want to automatically login when accessing phpMyAdmin locally while asking for a password when accessing remotely, you can achieve it using following snippet:

  1. if ($_SERVER["REMOTE_ADDR"] == "127.0.0.1") {
  2. $cfg['Servers'][$i]['auth_type'] = 'config';
  3. $cfg['Servers'][$i]['user'] = 'root';
  4. $cfg['Servers'][$i]['password'] = 'yourpassword';
  5. } else {
  6. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  7. }

注解

Filtering based on IP addresses isn’t reliable over the internet, use it only for local address.

Example for using multiple MySQL servers

You can configure any number of servers using $cfg['Servers'], following example shows two of them:

  1. <?php
  2. $cfg['blowfish_secret']='multiServerExample70518';
  3. //any string of your choice
  4. $i = 0;
  5. $i++; // server 1 :
  6. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  7. $cfg['Servers'][$i]['verbose'] = 'no1';
  8. $cfg['Servers'][$i]['host'] = 'localhost';
  9. // more options for #1 ...
  10. $i++; // server 2 :
  11. $cfg['Servers'][$i]['auth_type'] = 'cookie';
  12. $cfg['Servers'][$i]['verbose'] = 'no2';
  13. $cfg['Servers'][$i]['host'] = 'remote.host.addr';//or ip:'10.9.8.1'
  14. // this server must allow remote clients, e.g., host 10.9.8.%
  15. // not only in mysql.host but also in the startup configuration
  16. // more options for #2 ...
  17. // end of server sections
  18. $cfg['ServerDefault'] = 0; // to choose the server on startup
  19. // further general options ...

Google Cloud SQL with SSL

To connect to Google Could SQL, you currently need to disable certificate verification. This is caused by the certificate being issued for CN matching your instance name, but you connect to an IP address and PHP tries to match these two. With verification you end up with error message like:

  1. Peer certificate CN=`api-project-851612429544:pmatest' did not match expected CN=`8.8.8.8'

警告

With disabled verification your traffic is encrypted, but you’re open to man in the middle attacks.

To connect phpMyAdmin to Google Cloud SQL using SSL download the client and server certificates and tell phpMyAdmin to use them:

  1. // IP address of your instance
  2. $cfg['Servers'][$i]['host'] = '8.8.8.8';
  3. // Use SSL for connection
  4. $cfg['Servers'][$i]['ssl'] = true;
  5. // Client secret key
  6. $cfg['Servers'][$i]['ssl_key'] = '../client-key.pem';
  7. // Client certificate
  8. $cfg['Servers'][$i]['ssl_cert'] = '../client-cert.pem';
  9. // Server certification authority
  10. $cfg['Servers'][$i]['ssl_ca'] = '../server-ca.pem';
  11. // Disable SSL verification (see above note)
  12. $cfg['Servers'][$i]['ssl_verify'] = false;

参见

Using SSL for connection to database server, $cfg['Servers'][$i]['ssl'], $cfg['Servers'][$i]['ssl_key'], $cfg['Servers'][$i]['ssl_cert'], $cfg['Servers'][$i]['ssl_ca'], $cfg['Servers'][$i]['ssl_verify'], [https://bugs.php.net/bug.php?id=72048](https://bugs.php.net/bug.php?id=72048)\