'phpmyadmin ignores port on login page
I've built a docker container with the following (all on one container) :
- mysql Ver 8.0.29-0ubuntu0.20.04.2 for Linux on x86_64((Ubuntu))
- Apache/2.4.41 (Ubuntu)
- phpmyadmin 4:4.9.5+dfsg1-2
- PHP 7.4.3
On localhost/phpmyadmin, I fail to log in if I don't manually set the host directive in /etc/phpmyadmin/config.inc.php, for example:
$cfg['Servers'][$i]['host'] = "{$dbserver}:{$cfg['Servers'][$i]['port']}";$cfg['Servers'][$i]['host'] = $dbserver.':'.$dbport$cfg['Servers'][$i]['host'] = "{$dbserver}:3306";$cfg['Servers'][$i]['host'] = "localhost:3306";
Essentially, dbport is ignored in the config file
If I leave $cfg['Servers'][$i]['host'] = $dbserver it fails. even though $cfg['Servers'][$i]['port'] is set.
The file config.inc.php (default one, aside from the host directive):
<?php
/**
* Debian local configuration file
*
* This file overrides the settings made by phpMyAdmin interactive setup
* utility.
*
* For example configuration see
* /usr/share/doc/phpmyadmin/examples/config.sample.inc.php
* or
* /usr/share/doc/phpmyadmin/examples/config.manyhosts.inc.php
*
* NOTE: do not add security sensitive data to this file (like passwords)
* unless you really know what you're doing. If you do, any user that can
* run PHP or CGI on your webserver will be able to read them. If you still
* want to do this, make sure to properly secure the access to this file
* (also on the filesystem level).
*/
if (!function_exists('check_file_access')) {
function check_file_access($path)
{
if (is_readable($path)) {
return true;
} else {
error_log(
'phpmyadmin: Failed to load ' . $path
. ' Check group www-data has read access and open_basedir restrictions.'
);
return false;
}
}
}
// Load secret generated on postinst
if (check_file_access('/var/lib/phpmyadmin/blowfish_secret.inc.php')) {
require('/var/lib/phpmyadmin/blowfish_secret.inc.php');
}
/**
* Server(s) configuration
*/
$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 ''.
$i++;
/**
* Read configuration from dbconfig-common
* You can regenerate it using: dpkg-reconfigure -plow phpmyadmin
*/
if (check_file_access('/etc/phpmyadmin/config-db.php')) {
require('/etc/phpmyadmin/config-db.php');
}
/* Configure according to dbconfig-common if enabled */
if (!empty($dbname)) {
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
if (empty($dbserver)) $dbserver = 'localhost';
if (!empty($dbport) || $dbserver != 'localhost') {
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['port'] = $dbport;
}
$cfg['Servers'][$i]['host'] = $dbserver; // replace with $dbserver.':'.$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++;
}
/* Authentication type */
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
//$cfg['Servers'][$i]['host'] = 'localhost';
//$cfg['Servers'][$i]['connect_type'] = 'tcp';
//$cfg['Servers'][$i]['compress'] = false;
/* Uncomment the following to enable logging in to passwordless accounts,
* after taking note of the associated security risks. */
//$cfg['Servers'][$i]['AllowNoPassword'] = TRUE;
/**
* phpMyAdmin configuration storage settings.
*/
/* User used to manipulate with storage */
// $cfg['Servers'][$i]['controlhost'] = '';
// $cfg['Servers'][$i]['controlport'] = '';
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
/* Storage database and tables */
// $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';
/* Contrib / Swekey authentication */
// $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';
/*
* End of servers configuration
*/
/*
* Directories for saving/loading files from server
*/
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
/* Support additional configurations */
foreach (glob('/etc/phpmyadmin/conf.d/*.php') as $filename)
{
include($filename);
}
#
The file config-db.php
<?php
$dbuser='admin';
$dbpass='admin';
$basepath='';
$dbname='phpmyadmin';
$dbserver='localhost';
$dbport='3306';
$dbtype='mysql';
The file Dockerfile: (built with docker build -t test . and run with docker run -d -p 80:80 test)
FROM ubuntu:20.04
MAINTAINER Sheed
RUN apt-get update
RUN apt-get -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt -y install apache2 php libapache2-mod-php mysql-server php-mysql phpmyadmin
COPY ./config-db.php /etc/phpmyadmin/config-db.php
COPY ./config.inc.php /etc/phpmyadmin/config.inc.php
RUN cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
RUN a2enconf phpmyadmin
COPY ./init.sh /init.sh
COPY ./start.sh /start.sh
RUN bash /init.sh
CMD ["bash", "start.sh"]
The file init.sh:
#!/bin/bash
service mysql start
mysql -u root --password= -e "CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';"
mysql -u root --password= -e "GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';"
mysql -u root --password= -e "FLUSH PRIVILEGES;"
The file start.sh:
#!/bin/bash
service mysql start
apachectl -D FOREGROUND
By manually setting as examplified above and setting dbport, the header on PHPMyAdmin shows : localhost:3306:3306,twice the port, which is strange that it does include the port there but not for login requests
Solution 1:[1]
Fact
You have
$dbport='3306';
and
$cfg['Servers'][$i]['host'] = "{$dbserver}:{$cfg['Servers'][$i]['port']}";
So, putting the host and the port together you get the resulting duplicate port, because
"host:port" . ":" . "port" === "host:port:port"
So, the technical answer to your question is that you get duplicated ports because you have added the port to the host and left the port value for the port.
Theory
Even though the reason of your port being duplicated is clear (see the Fact section), we need to know why you need to duplicate the port.
First of all, you will need to check whether you really need to duplicate the port (changing $dbport to '' is a test, for instance) and you will also need to look into the error that you get from PHPMyAdmin. If you want to research this further, you can ask a separate question about the cause of the issue here on stackoverflow.
This is just an educated guess, but to me it seems that your Docker container uses port 3306 (the port you needed to add to the host) and, your Docker container also uses PORT 3306 to reach your database.
A simplification would be possible to make sure that you have a container that's reachable from port 80 for example and acts as a proxy to your other container that can be reached at port 3306. But this is only an opinion, the actual answer to your question can be found in the Fact section.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lajos Arpad |
