Skip to the fix
PHPSolvedThe fix first, then the reason

Newest fixes

Paloma Quesada in phpMyAdmin, nginx and Apache | | 7 min

localhost/phpmyadmin does not open: the checks in order

If localhost/phpmyadmin does not open, check the port, the alias, PHP and then MySQL, in that order. The login is a MySQL account, not a phpMyAdmin one.

Open server tower on a wooden desk lit by a torch
On this page
  1. Check 1: is anything listening, and where
  2. Check 2: the alias, behind 404 and 403
  3. Check 3: PHP, behind 500, 502 and blank pages
  4. Check 4: the page loads, MySQL doesn't answer
  5. Check 5: the login, and the default password that doesn't exist
  6. Before you reinstall

Four things have to work, one after the other: a web server listening on the port you typed, a rule that maps /phpmyadmin to the program's files, PHP running them, and a MySQL server that accepts your login. What the browser shows tells you which one failed.

In the browserBroken partGo to
"Refused to connect", "can't reach this page"Web server or portCheck 1
Another site, or the server's default pageWrong port or wrong virtual hostCheck 1
404 Not FoundThe aliasCheck 2
403 ForbiddenAccess rulesCheck 2
The PHP source, or a file downloadPHP isn't connectedCheck 3
500, 502 or a blank pagePHP failsCheck 3
A phpMyAdmin page with a red errorMySQLCheck 4
A login form that rejects youThe MySQL accountCheck 5

Open http://localhost/phpmyadmin/ with the http://, and with the slash at the end. Typed bare into the address bar, a browser may search for it or try https instead.

Check 1: is anything listening, and where

A default Apache or nginx uses port 80, which you don't type. XAMPP uses 80 as well. Other setups use another port, and then it belongs in the address, for example http://localhost:8080/phpmyadmin/. A short PHP script run from the command line shows which ports answer:

phpran on PHP 8.2.8
<?php
$ports = [80 => 'web', 443 => 'web, TLS', 8080 => 'web, alternative', 8888 => 'web, alternative', 3306 => 'MySQL'];

foreach ($ports as $port => $use) {
    $fp = @fsockopen('127.0.0.1', $port, $errno, $error, 2);
    printf("%-5d %-17s %s\n", $port, $use, $fp ? 'open' : $error);
    if ($fp) {
        fclose($fp);
    }
}

On a machine with none of these services the result is a column of refusals:

output
80    web               Connection refused
443   web, TLS          Connection refused
8080  web, alternative  Connection refused
8888  web, alternative  Connection refused
3306  MySQL             Connection refused

"Connection refused" means that no program is listening there. A timeout instead points at a firewall. fsockopen reports both.

If the script says open but the page is someone else's, ask the system which program holds the port. On Linux, with the ss options for listening, numeric, TCP and process:

bash
sudo ss -lntp | grep -E ':(80|443|3306)\b'

On Windows the XAMPP documentation names the usual suspects: a second web server such as IIS, or other software that grabbed port 80 first. Only one program can have it. Its FAQ also covers a second MySQL: two servers can't start on the same port.

If nothing listens on port 80, start the web server and read its answer. Both servers can test their own configuration, and a typo in an unrelated virtual host is enough to keep them down:

bash
sudo nginx -t
sudo apachectl configtest
sudo systemctl status nginx apache2 --no-pager

Running both Apache and nginx on the same port is a frequent reason for a service that "won't start". Pick one, or move one to another port.

One more command helps before you go on, because it leaves browser caches and saved redirects out of the picture:

bash
curl -sI http://localhost/phpmyadmin/

Read the status line, the Server header and, if there is one, Location. The header names the program that really answered, which settles the question of Apache or nginx. A Location that leads to https or to another host name means a redirect in some virtual host caught the request before phpMyAdmin was involved. If curl gets a 200 and the browser doesn't, clear the site data for localhost in that browser.

Check 2: the alias, behind 404 and 403

Installed as a package, phpMyAdmin lives outside the web root (in /usr/share/phpmyadmin, according to the file list of Ubuntu's package), so the web server needs a rule for the address. In Apache that's an Alias together with permission for the directory:

apache
Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
    DirectoryIndex index.php
    Require local
</Directory>

Apache's page on mod_alias has the two details that decide between 404 and 403. If the URL path ends with a slash, /phpmyadmin without the slash isn't matched, and you get 404. And an alias to a directory outside the document root may need its own Require line, or the answer is 403.

Require local admits only the machine itself. That's what you want on a desktop. It also explains a 403 that appears when you open the page from a phone or another computer in the house: XAMPP ships the same restriction, and its FAQ advises against loosening it.

Debian and Ubuntu packages keep their web server configuration in /etc/phpmyadmin, as the phpMyAdmin installation page says. It also says that this automatic part works for Apache and lighttpd. nginx isn't on that list, so on nginx a fresh package install gives 404 until you write the location yourself. A complete block is in phpMyAdmin with nginx on Ubuntu.

A downloaded archive has another cause of 404: the folder is called something like phpMyAdmin-5.2.2-all-languages. Rename it, and remember that phpMyAdmin and phpmyadmin are different names on a Linux file system.

Check 3: PHP, behind 500, 502 and blank pages

A browser that shows <?php or offers a download has reached the right folder on a server without a working PHP handler. On nginx that's a missing PHP location for this path, or a SCRIPT_FILENAME that doesn't match the alias. A 502 means that nginx found no PHP process at the other end of the socket, which has its own page.

For a 500 or a blank page, the message exists, only not in the browser. Look into the web server's error log first (/var/log/apache2/error.log on Ubuntu; for nginx, sudo nginx -T | grep error_log prints the path), then into the PHP log, and read the last lines right after you reload the page.

Missing extensions are the most common content of that log. This script checks the ones that the requirements page and the configuration manual mention. Save it as a file, open it through the web server, then delete it:

phpran on PHP 8.2.8
<?php
$wanted = [
    'mysqli'   => 'talks to the database',
    'session'  => 'required',
    'hash'     => 'required',
    'ctype'    => 'required',
    'json'     => 'required',
    'mbstring' => 'strongly recommended',
    'openssl'  => 'suggested with cookie login',
    'sodium'   => 'encrypts the login cookie since 5.2.0',
    'zip'      => 'zip imports',
];
foreach ($wanted as $name => $why) {
    printf("%-9s %-8s %s\n", $name, extension_loaded($name) ? 'ok' : 'MISSING', $why);
}
echo version_compare(PHP_VERSION, '7.2.5', '>=') ? "PHP version ok\n" : "PHP too old\n";
real output
mysqli    ok       talks to the database
session   ok       required
hash      ok       required
ctype     ok       required
json      ok       required
mbstring  ok       strongly recommended
openssl   ok       suggested with cookie login
sodium    ok       encrypts the login cookie since 5.2.0
zip       ok       zip imports
PHP version ok

The browser matters here. The command line can load a different php.ini and a different set of modules from the one behind your web server, and a script that says ok in the terminal proves nothing about the page. After installing a module, restart PHP-FPM or Apache.

A blank page without any log entry has one more documented cause. The phpMyAdmin FAQ suggests setting $cfg['OBGzip'] to false and turning zlib.output_compression off.

Check 4: the page loads, MySQL doesn't answer

Now you see phpMyAdmin's own layout and a line like mysqli::real_connect(): (HY000/2002). The number and the words after it decide what to do:

phpran on PHP 8.2.8
<?php
$socket = getenv('LAB_SOCKET') ?: null;
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$tries = [
    'wrong socket path' => ['localhost', 'root', '', '', null, '/tmp/no-such.sock'],
    'nothing on port'   => ['127.0.0.1', 'root', '', '', 1],
    'wrong account'     => ['localhost', 'nobody_here', 'x', '', null, $socket],
];
foreach ($tries as $what => $args) {
    try {
        new mysqli(...$args);
    } catch (mysqli_sql_exception $e) {
        printf("%-17s (HY000/%d): %s\n", $what, $e->getCode(), $e->getMessage());
    }
}
real output
wrong socket path (HY000/2002): No such file or directory
nothing on port   (HY000/2002): Connection refused
wrong account     (HY000/1045): Access denied for user 'nobody_here'@'localhost' (using password: YES)

2002, No such file or directory. PHP looked for a socket file that isn't there. Either MySQL is stopped, or it uses another path. SHOW VARIABLES LIKE 'socket' from a working console gives the path. Put it into $cfg['Servers'][$i]['socket'], or switch to TCP.

2002, Connection refused. TCP was tried and nobody answered on that port. Start MySQL, or correct the port.

Switching to TCP means writing the address and not the name:

php
<?php
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '3307';

The configuration manual warns that the port is ignored when the host is localhost, because the connection then goes through the socket. This is the trap behind most "I changed the port and nothing happened" reports. In Docker, the host is the name of the database container's service. Inside the phpMyAdmin container, localhost is that container.

Check 5: the login, and the default password that doesn't exist

phpMyAdmin has no accounts and no default password. The form passes your name and password to MySQL or MariaDB, and the server decides. So "what is the phpMyAdmin password" is really a question about the database server:

SetupWhat to try
XAMPP, untouchedroot with no password, according to the XAMPP FAQ
MySQL package on UbuntuAn account you create yourself: root uses auth_socket and can't log in here
MariaDB on Debian or UbuntuThe same, its root uses unix_socket
DockerWhatever the database container was started with, for example MYSQL_ROOT_PASSWORD
Shared hostingThe database user from the hosting panel

An empty password is refused by phpMyAdmin itself, even if MySQL would accept it. $cfg['Servers'][$i]['AllowNoPassword'] is false by default, and it's better to set a password than to change that. For Ubuntu and Debian, create an account from a shell:

sql
CREATE USER 'paloma'@'localhost' IDENTIFIED BY 'a long random password';
GRANT ALL PRIVILEGES ON shop.* TO 'paloma'@'localhost';

Run these after sudo mysql, and grant only the databases you work on. If the login is still refused, the host part of the account is the next suspect, and error 1045 goes through it piece by piece.

When the account is right and the form still comes back, look at the cookie. The password is kept in an encrypted cookie between pages, so a browser that blocks cookies for localhost can't stay logged in. An empty or short blowfish_secret makes phpMyAdmin generate a temporary key that lasts only for the session. It has to be 32 bytes long, and the secret generator produces the whole line for config.inc.php.

Before you reinstall

Reinstalling the package fixes neither a port conflict nor a MySQL account, which are the two ends of this list. It can also replace a configuration that worked. Copy /etc/phpmyadmin (or config.inc.php from a manual install) somewhere first. Then take the checks in order once more and stop at the first one that fails, because everything after it is noise.

Same subject