无法让 phpmyadmin 列出多个服务器

Can't get phpmyadmin to list multiple servers

我试图让服务器下拉列表出现在登录屏幕中,但它不会,我已经在 /etc/phpmyadmin/config.inc.php 中添加了两个服务器,但到目前为止可以一次只能让它与一个一起工作。如果我增加变量 $i,它只会导致一个半空白屏幕,上面没有任何有形的数据库信息,如果我将其注释掉 $i,它默认为第二台服务器。

第一台服务器是localhost,第二台是docker实例,config.inc.php的相关内容是

if (!empty($dbname)) {
    /* Authentication type */
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    $cfg['Servers'][$i]['verbose'] = 'db on the pc'; //provide hostname and port if other than default
    /* Server parameters */
    if (empty($dbserver)) $dbserver = 'localhost';
    $cfg['Servers'][$i]['host'] = $dbserver;

    if (!empty($dbport) || $dbserver != 'localhost') {
        $cfg['Servers'][$i]['connect_type'] = 'tcp';
        $cfg['Servers'][$i]['port'] = $dbport;
    }
    //$cfg['Servers'][$i]['compress'] = false;
    /* Select mysqli if your server has it */
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    /* Optional: User for advanced features */
    $cfg['Servers'][$i]['controluser'] = $dbuser;
    $cfg['Servers'][$i]['controlpass'] = $dbpass;
    /* Optional: Advanced phpMyAdmin features */
    $cfg['Servers'][$i]['pmadb'] = $dbname;
    $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';

    /* Uncomment the following to enable logging in to passwordless accounts,
     * after taking note of the associated security risks. */
    // $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

    /* Advance to next server for rest of config */
    $i++;
}

//$i++;
$cfg['Servers'][$i]['verbose'] = 'second_db'; //provide hostname and port if other than default
$cfg['Servers'][$i]['host'] = '172.18.0.1:3307'; //provide hostname and port if other than default
$cfg['Servers'][$i]['user'] = 'user';   //user name for your remote server
$cfg['Servers'][$i]['password'] = 'pass';  //password
$cfg['Servers'][$i]['auth_type'] = 'config';

如您所见,我已将 $i 注释掉作为临时解决方案,因此它现在默认为第二台服务器 (172.18.0.1)。值得注意的是,我安装了 valet 并注意到一些有趣的行为,因为我不再使用 localhost/phpmyadmin 访问 phpmyadmin,而是 phpmyadmin.test 我通过在 phpmyadmin 文件夹中使用 valet 命令来访问它。我的问题是如何让两个服务器都显示在登录屏幕上?

编辑:如果我将第二个服务器放在 if 子句中,在 $i++ 之后,登录屏幕将默认为第一个并忽略第二个

我最终将配置更改为分配给它的配置 here,现在我有服务器下拉列表,问题已解决。

$i = 0;
// The $cfg['Servers'] array starts with $cfg['Servers'][1].  Do not use $cfg['Servers'][0].
// You can disable a server config entry by setting host to ''.
$hosts = [
'172.18.0.1:3307',
'localhost'
];
foreach($hosts as $host) {
$i++;
    $cfg['Servers'][$i]['host']     = $host;
    $cfg['Servers'][$i]['port']     = '';
    $cfg['Servers'][$i]['socket']   = '';
    $cfg['Servers'][$i]['connect_type']     = 'tcp';
    $cfg['Servers'][$i]['extension']        = 'mysql';
    $cfg['Servers'][$i]['compress'] = FALSE;
    $cfg['Servers'][$i]['controluser']      = 'pma';
    $cfg['Servers'][$i]['controlpass']      = 'pmapass';
    $cfg['Servers'][$i]['auth_type']        = 'cookie';
    $cfg['Servers'][$i]['user']     = '';
    $cfg['Servers'][$i]['password'] = '';
    $cfg['Servers'][$i]['only_db']  = '';
    $cfg['Servers'][$i]['verbose']  = '';
    $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]['designer_coords'] = 'pma_designer_coords';
}
$i++;