


introduction
phpMyAdmin is a widely used MySQL/MariaDB database management tool. In daily development and operation and maintenance, we often need to manage multiple database servers, such as the database of the local development environment, the database in the Docker container, and the database of the remote production environment. However, many users will encounter the problem that the phpMyAdmin login interface only displays one server, or the configuration does not take effect when trying to configure multiple servers. This is usually caused by incorrect server definition in the config.inc.php configuration file.
This article will explore the correct method of multi-server configuration in phpMyAdmin. Based on the officially recommended configuration mode, it will guide you how to effectively manage multiple database connections.
Analysis of common configuration misunderstandings and problems
When configuring multiple servers, users usually try to manually increment the $i variable to define $cfg['Servers'][$i], or place the server configuration in an inappropriate conditional statement. For example, the following are common mistake attempts:
// Incorrect configuration attempt example if (!empty($dbname)) { $cfg['Servers'][$i]['host'] = 'localhost'; // ... Other configuration $i; // Increment within the conditional block may cause the second server to be not correctly recognized} // The configuration of the second server // $i ; // If incremented here again, it may cause the index $cfg['Servers'][$i]['host'] = '172.18.0.1:3307'; // ... Other configurations
The problem with this configuration is:
- Lifecycle and scope of $i variable : If you increment $i in a conditional statement or a specific logical block, it may cause its value to be discontinuous or not as expected in subsequent global configurations.
- Configuration override or skip : Incorrect $i management may cause phpMyAdmin to recognize only the first or last defined server, or a blank page appears because the index of the configuration array is handled incorrectly.
- Lack of unified management : When the number of servers increases, this manual maintenance becomes cumbersome and error-prone.
How to correctly configure multiple servers
phpMyAdmin official provides an elegant and robust multi-host configuration solution, which dynamically generates server configurations by looping through a list of hosts. This approach ensures that each server is correctly assigned an independent configuration index and is easy to scale and maintain.
Typically, you can find the main configuration file named config.inc.php in the installation directory of phpMyAdmin (e.g. /etc/phpmyadmin/ or phpmyadmin/libraries/). Please edit this file.
Sample configuration code
The following is an example of config.inc.php multi-server configuration based on the official recommended mode:
<?php /* * Generated by phpMyAdmin * all config for servers */ declare(strict_types=1); // Make sure the server index starts at 1, phpMyAdmin does not use $cfg['Servers'][0] $i = 0; // Define a list of all database hosts that need to be managed// Format 'hostname:port' or 'hostname' $hosts = [ 'localhost', // Local MySQL server'172.18.0.1:3307', // Docker container or other remote MySQL server// More servers can be added here // 'remote.database.com:3306', ]; // traverse the host list and configure phpMyAdmin server connection foreach foreach ($hosts as $host) { $i ; // Increment the server index every loop, ensuring that it starts from 1 and is continuous // Basic connection parameter $cfg['Servers'][$i]['host'] = $host; $cfg['Servers'][$i]['port'] = ''; // If the host name already contains a port, leave blank here $cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['connect_type'] = 'tcp'; // Connection type, usually tcp $cfg['Servers'][$i]['extension'] = 'mysqli'; // It is recommended to use mysqli to extend $cfg['Servers'][$i]['compress'] = false; // Whether to enable compression// Authentication method and user credentials $cfg['Servers'][$i]['auth_type'] = 'cookie'; // It is recommended to use cookie authentication, which is highly secure// If you use the 'config' authentication type, you need to directly specify the user and password here// $cfg['Servers'][$i]['auth_type'] = 'config'; // $cfg['Servers'][$i]['user'] = 'your_username'; // $cfg['Servers'][$i]['password'] = 'your_password'; // Optional: Set an easy-to-recognize alias for each server $cfg['Servers'][$i]['verbose'] = ($host === 'localhost') ? 'Local development database' : 'Docker container database'; // The control users and databases required for advanced functions of phpMyAdmin // These are internal functions used to store bookmarks, relationships, etc., and require a special user and database. // If you do not use these advanced features, you can leave it blank or comment out. $cfg['Servers'][$i]['controluser'] = 'pma'; // To control the user, you need to create $cfg['Servers'][$i]['controlpass'] = 'pmapass'; // To control the user password// phpMyAdmin controls the database name $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark'; $cfg['Servers'][$i]['relation'] = 'pma__relation'; $cfg['Servers'][$i]['table_info'] = 'pma__table_info'; $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords'; $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages'; $cfg['Servers'][$i]['column_info'] = 'pma__column_info'; $cfg['Servers'][$i]['history'] = 'pma__history'; $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs'; $cfg['Servers'][$i]['tracking'] = 'pma__tracking'; $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig'; $cfg['Servers'][$i]['recent'] = 'pma__recent'; $cfg['Servers'][$i]['favorite'] = 'pma__favorite'; $cfg['Servers'][$i]['users'] = 'pma__users'; $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups'; $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding'; $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches'; $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns'; $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings'; $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates'; // Other optional configurations $cfg['Servers'][$i]['only_db'] = ''; // Restrict this server to display only specific databases// $cfg['Servers'][$i]['AllowNoPassword'] = true; // Allow password-free login, it is highly deprecated in production environments}
Configuration details
- $i = 0; : Initialize the server index counter. phpMyAdmin's server array $cfg['Servers'] starts with index 1.
- $hosts = [...] : Define an array containing all database host addresses. Each element can be in the form of 'hostname' or 'hostname:port'.
- foreach ($hosts as $host) : Iterates over the $hosts array. In each loop:
- $i ; : Increment $i to ensure that each server is assigned a unique continuous index starting from 1.
- $cfg['Servers'][$i]['host'] = $host; : Sets the host address of the current server.
- $cfg['Servers'][$i]['port'] = ''; : If the port is already included in the host name (such as 172.18.0.1:3307), then leave it blank; otherwise, if the port is not the default 3306, it needs to be specified explicitly here.
- $cfg['Servers'][$i]['connect_type'] = 'tcp'; : Specify the connection type, usually TCP/IP.
- $cfg['Servers'][$i]['extension'] = 'mysqli'; : It is recommended to use mysqli extension for better performance and security.
- $cfg['Servers'][$i]['auth_type'] = 'cookie'; : It is highly recommended to use cookie authentication. This means that the user needs to enter a username and password every time he logs in.
- config authentication type : If you choose 'config' authentication (such as the second server in the original question), you must provide $cfg['Servers'][$i]['user'] and $cfg['Servers'][$i]['password'] directly in the configuration. This method hardcodes credentials into configuration files, which are less secure and are especially not suitable for production environments.
- $cfg['Servers'][$i]['verbose'] : Set an easy-to-recognize alias for each server, which will be displayed in the drop-down menu of the phpMyAdmin login interface.
- $cfg['Servers'][$i]['controluser'] / $cfg['Servers'][$i]['controlpass'] / $cfg['Servers'][$i]['pmadb'] : These are the configurations required for advanced features of phpMyAdmin (such as bookmarks, relationship diagrams, etc.). You need to create a user in MySQL named pma (or another name you specified) and grant it the necessary permissions to the phpmyadmin (or another name you specified) database. If these advanced features are not required, you can not configure them.
Things to note
- Configuration file location : config.inc.php is usually located in the installation directory of phpMyAdmin or /etc/phpmyadmin/. Please make sure that you modify the correct configuration file.
- Permissions Issue : Ensure that web server users (such as www-data or apache) have read permissions to the config.inc.php file.
- Web server restart : After modifying config.inc.php, you sometimes need to restart the web server (such as Apache or Nginx) and the PHP-FPM service to ensure that the configuration takes effect.
- Security :
- Always give priority to using cookie authentication types.
- Avoid using config authentication types in production environments, because it stores database credentials plaintext in configuration files.
- Set a strong password for the controller and restrict its permissions to phpmyadmin control the database.
- Development environments such as Valet : If you use Valet or other local development tools, the access address of phpMyAdmin may change from localhost/phpmyadmin to custom domain names such as phpmyadmin.test. This will not affect the configuration logic of multiple servers, but make sure you are accessing phpMyAdmin via the correct URL.
- Port and hostname : When the hostname contains a port (such as 172.18.0.1:3307), $cfg['Servers'][$i]['port'] can be left blank. If the hostname does not contain a port and the port is not the default 3306, $cfg['Servers'][$i]['port'] must be explicitly set.
Summarize
By adopting the above-mentioned configuration method based on foreach loops, you can manage multiple database servers clearly and efficiently in phpMyAdmin. This method not only solves the problem that the login interface does not display all servers, but also improves the readability and maintainability of the configuration. Following the guidance of this tutorial, you will be able to easily switch between different database environments, greatly improving your database management experience.
The above is the detailed content of Detailed explanation of phpMyAdmin multi-server configuration: Solve the problem of not displaying multiple database connections on the login interface. For more information, please follow other related articles on the PHP Chinese website!

This article aims to help developers understand and resolve the “Missing X-FC-NonceHeader” error encountered when using the Flashsoft API. The article will explain the role of X-FC-Nonce Header, provide a PHP code example, showing how to generate a Nonce value that meets the requirements and add it to the HTTP request header, thus successfully calling the API. Through this article, developers can avoid this error and successfully complete API integration.

This tutorial details how to efficiently reconstruct multidimensional associative arrays in PHP. By converting the columnar data of the original array into a row structure with a specific field (such as name) as the key, and dynamically mapping other related attributes (such as ranking and amount), we help developers solve data conversion problems and improve data processing flexibility and readability.

This tutorial aims to solve common problems in dynamic SQL queries and date iterations in PHP functions, especially to avoid global variables and improper function calls. We will explore in-depth how to build a safe, efficient and easy-to-maintain database operation logic through data-driven iteration patterns, PDO preprocessing statements and dependency injection to optimize code structure and performance.

This document is intended to guide developers how to use PHP to remove Unicode uninterrupted space characters (\u00a0) from string arrays. With sample code and detailed explanations, you will learn how to correctly identify and filter out these special characters, ensuring the accuracy and efficiency of data cleaning.

This article describes how to use the PHP Guzzle library to send HTTP requests and parse XML response data. It focuses on how to process XML data with namespaces and provides sample code to illustrate how to extract specific fields in XML, such as ID and NAME, and ultimately convert the data into a key => value array.

Use the GD library to achieve PHP image scaling. First, obtain the original image size and type, create image resources, calculate the new size according to the maximum width, create a new image of transparent background, resample and copy and save, and finally free memory.

To create a PHP object, you need to define the class first, and then instantiate it with the new keyword. For example, after defining the Car class and setting properties and constructing methods, create an object through $myCar=newCar("red","Toyota"), and then use -> to access its properties and methods, such as $myCar->color and $myCar->showInfo(). Each object has independent data and can create multiple instances.

Useincludeforoptionalfiles,asitcontinuesexecutiononfailure.2.Userequireforessentialfiles,asmissingfilesstopexecution.3.Useinclude_onceandrequire_oncetopreventduplicateinclusions.4.PreferDIRforreliablefilepaths.Choosingtherightmethodensurespropercodeo


Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools