💾

phpmyadmin

3 notes  •  Databases

Manually Upgrade phpMyAdmin on Ubuntu

Upgrade phpMyAdmin to the latest version when the apt package lags behind, keeping existing configuration files intact.

Steps

  1. Back up the existing installation:
    sudo mv /usr/share/phpmyadmin /usr/share/phpmyadmin.bak
  2. Download and extract the latest release:
    wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
    unzip phpMyAdmin-latest-all-languages.zip
  3. Move files into place:
    sudo mkdir /usr/share/phpmyadmin
    sudo mv phpMyAdmin-*/* /usr/share/phpmyadmin/
  4. Point to existing config directories (required when originally installed via apt):
    sudo nano /usr/share/phpmyadmin/libraries/vendor_config.php
    Update these constants:
    define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');
    define('CONFIG_DIR', '/etc/phpmyadmin/');
  5. Set permissions:
    sudo chown -R www-data:www-data /usr/share/phpmyadmin

Verify

Open phpMyAdmin in a browser - the new version appears in the footer.

Notes

  • Prevent apt from downgrading: sudo apt-mark hold phpmyadmin.

Add Remote MySQL Hosts to phpMyAdmin

Configure phpMyAdmin to connect to multiple remote MySQL servers from a single interface.

Edit config.inc.php

/* Server 1 - Production */
$i++;
$cfg['Servers'][$i]['auth_type']    = 'cookie';
$cfg['Servers'][$i]['verbose']      = 'Production Server';
$cfg['Servers'][$i]['host']         = '10.0.0.1';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress']     = false;

/* Server 2 - Staging */
$i++;
$cfg['Servers'][$i]['auth_type']    = 'cookie';
$cfg['Servers'][$i]['verbose']      = 'Staging Server';
$cfg['Servers'][$i]['host']         = '10.0.0.2';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress']     = false;

Grant Remote Access on MySQL

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'phpMyAdmin-IP'
    IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Verify

Open phpMyAdmin - a server dropdown appears at login.

Notes

  • Ensure port 3306 is open between phpMyAdmin server and remote MySQL hosts.
  • Restrict MySQL remote access to specific IPs rather than %.

Install and Secure phpMyAdmin with Nginx on Ubuntu 20.04

Install phpMyAdmin on Ubuntu 20.04 with Nginx and apply security hardening.

Prerequisites

  • Ubuntu 20.04 with Nginx and PHP-FPM
  • MySQL or MariaDB running
  • Sudo access

Step 1 - Install phpMyAdmin

sudo apt update
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
sudo phpenmod mbstring
sudo systemctl restart php8.1-fpm

Step 2 - Create a Dedicated MySQL User

sudo mysql -u root -p
CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'StrongPass!';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Step 3 - Configure Nginx

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

Add to your Nginx server block:

location /phpmyadmin {
    root /var/www/html;
    index index.php;
    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
sudo nginx -t && sudo systemctl reload nginx

Step 4 - Harden Access

  • Rename the URL: rename the symlink to something non-obvious (e.g. dbmgr2025).
  • Add HTTP Basic Auth:
    sudo apt install apache2-utils
    sudo htpasswd -c /etc/nginx/.htpasswd adminuser
    Add to the Nginx location block:
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
  • Restrict by IP:
    allow 203.0.113.5;
    deny all;