无法让 phpmyadmin 列出多个服务器

Posted

技术标签:

【中文标题】无法让 phpmyadmin 列出多个服务器【英文标题】:Can't get phpmyadmin to list multiple servers 【发布时间】:2021-12-14 01:11:49 【问题描述】:

我正在尝试让服务器下拉菜单出现在登录屏幕中,但它不会,我已经在 /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++ 之后,登录屏幕将默认为第一个,而忽略第二个

【问题讨论】:

查看此示例:apt-browse.org/browse/ubuntu/bionic/universe/all/phpmyadmin/… 或者,根本不要使用 $i 并手动设置该数字(注意它必须从 1 开始,而不是 0) 我看到你解决了这个问题,但如果你想回到它,我建议转储整个 $cfg 数组来检查它,看起来你的代码中没有正确设置一些东西,并且查看变量的内容应该有助于解开一些谜团。 【参考方案1】:

我最终将配置更改为分配给 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++;

【讨论】:

以上是关于无法让 phpmyadmin 列出多个服务器的主要内容,如果未能解决你的问题,请参考以下文章

phpMyAdmin 的单点登录

无法让PHPMyAdmin连接到Amazon RDS实例

phpMyAdmin 使用 PHP 7.0.0 RC7 “无法登录到 MySQL 服务器”

phpMyAdmin:PHP 致命错误 - 无法重新声明 PMA_checkLink()

无法使用 root 和无密码登录 phpmyadmin

phpMyAdmin提示“无法在发生错误时创建会话,请检查 PHP 或网站服务器日志,并正确配置 PHP 安装。”