phpMyAdmin: how it works and how to fix it
phpMyAdmin is a set of PHP pages that manage MariaDB from the browser. It is not a separate server: Apache serves it, PHP runs it, and it logs in to MariaDB as whatever user you type on the login page. So a phpMyAdmin problem is always one of three things:
| Symptom | Which part | Section |
|---|---|---|
404 at /phpmyadmin | Apache does not know about phpMyAdmin | Fix 404 |
| PHP code shown or a download | PHP not working in Apache | Apache |
| Login page appears but login fails | MariaDB user or password | Login errors |
The installer questions
sudo apt install phpmyadmin asks questions in a blue screen. Keys: arrows move, Spacebar ticks [*], Tab jumps to <Ok>, Enter confirms.
| Question | What it does |
|---|---|
| Web server to reconfigure automatically | Adds phpMyAdmin's config to Apache. You must press Spacebar on apache2 so it shows [*]. Pressing Enter alone selects nothing, and you get a 404 later. |
| Configure database with dbconfig-common? | Creates a small phpmyadmin database and user that phpMyAdmin uses for its own settings (bookmarks, history). It is not your login. |
| MySQL application password | The password of that internal phpmyadmin user. You never type it on the login page. |
The answers are saved and can be changed any time with sudo dpkg-reconfigure phpmyadmin (how dpkg-reconfigure works).
Fix: 404 Not Found
Apache was not told about phpMyAdmin. First check:
ls /etc/apache2/conf-enabled/ | grep -i phpmyadmin # nothing = not enabled
sudo debconf-show phpmyadmin | grep webserver # empty = apache2 was not ticked
Then use one of these:
A. Answer the question again (easiest):
sudo dpkg-reconfigure phpmyadmin
Tick apache2 with Spacebar. If it asks to reinstall the database, choose No (keeps what is there). Then sudo systemctl reload apache2.
B. Enable the config yourself:
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin
sudo systemctl reload apache2
ln: ... File exists on the first line is fine: skip to the next line.
C. The lab sheet method: add Include /etc/phpmyadmin/apache.conf at the end of /etc/apache2/apache2.conf, then sudo apache2ctl configtest and restart.
Use only one method. Using B and C together loads phpMyAdmin twice, and Apache warns Alias /phpmyadmin overlaps an earlier Alias. If you see that, remove one of them.
Login errors
The phpMyAdmin login page is a MariaDB login. Whatever works with mysql -u USER -p in the terminal works here, and the other way round. Test in the terminal first:
mysql -u Nypuser -p
| Error | Cause | Fix |
|---|---|---|
#1045 Access denied for user 'Nypuser'@'localhost' | User does not exist for localhost, or wrong password | sudo mariadb, then SELECT User, Host FROM mysql.user;. See users and hosts. |
#1045 for root | root uses unix_socket (no password logins), or the password is wrong | Log in as Nypuser instead. Why root is different. |
| Login works but no databases on the left | The user has no permissions | GRANT them. See permissions. |
#2002 No such file or directory / Cannot log in to the MySQL server | MariaDB is not running | sudo systemctl start mariadb, then check systemctl status mariadb. |
mysqli extension is missing | PHP cannot talk to MariaDB | sudo apt install php-mysql, then sudo systemctl restart apache2. |
| Login page just reloads, no error | Session or cookie problem | Clear the browser's cookies for localhost, or try a private window. Check the card is not full (df -h /). |
Usernames and passwords are case-sensitive: Nypuser is not nypuser.
Warnings you can ignore
- The phpMyAdmin configuration storage is not completely configured: only extra features are missing.
- A newer version of phpMyAdmin is available: the Debian version is updated through
apt. - The configuration file now needs a secret passphrase (blowfish_secret): only appears on hand-installed copies; the Debian package sets it.
Doing the same thing without phpMyAdmin
Everything you click in phpMyAdmin is SQL underneath. phpMyAdmin even shows the SQL it ran in a box at the top of the page after each action. Learning to read that box is the quickest way to learn SQL. See MariaDB and SQL.
Start over completely
sudo apt purge phpmyadmin -y
sudo apt autoremove -y
sudo apt install phpmyadmin -y
purge deletes phpMyAdmin's saved answers, so every question is asked again. Your own databases (MySensor etc.) are not touched.