This is an old revision of the document!


phpMyAdmin

Remove repository-installation

  1. Purge the Package and dependencies if you previously installed it from Debian's repository: The purge flag instructs apt to erase the package binaries along with its main configuration files.
    sudo apt purge phpmyadmin
    sudo apt autoremove --purge
  2. Delete remaining configuration & web root leftovers: apt sometimes leaves empty directories or user-modified configuration blocks untouched. Wipe them completely with the following commands:
    sudo rm -rf /etc/phpmyadmin
    sudo rm -rf /usr/share/phpmyadmin
    sudo rm -rf /var/lib/phpmyadmin
  3. Clear web server configurations: remove apache's setup link and reload the service:
    sudo rm -f /etc/apache2/conf-available/phpmyadmin.conf
    sudo rm -f /etc/apache2/conf-enabled/phpmyadmin.conf
    sudo systemctl reload apache2
  4. Remove the phpMyAdmin storage database: If dbconfig-common didn't automatically drop the internal tracking database, log into your MySQL/MariaDB terminal to remove it:
    sudo mysql -u root -p
    DROP DATABASE IF EXISTS phpmyadmin;
    DROP USER IF EXISTS 'phpmyadmin'@'localhost';
    FLUSH PRIVILEGES;
    # check databases and users
    SHOW DATABASES;
    SELECT User, Host FROM mysql.user;
    EXIT;

Installation

  1. We will not use any of the standard paths used in Debian or other distributions. All files related to phpMyAdmin will remain in the custom path (e.g. /home/user/html/phpMyAdmin) where we download the files and which is the easiest way for maintenance and later version upgrades.

  2. Navigate to /home/user/html, download the latest stable tarball, extract it, and rename the folder:
    cd /home/user/html
    sudo wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-english.tar.gz
    sudo tar -xvzf phpMyAdmin-latest-english.tar.gz
    sudo rm phpMyAdmin-latest-english.tar.gz
    sudo mv phpMyAdmin-*-english phpmyadmin
  3. Create the temporary folder required by phpMyAdmin and assign proper web server ownership:
    $ sudo mkdir -p /home/user/html/phpMyAdmin/tmp
    $ sudo chown -R www-data:www-data /home/user/html/phpMyAdmin
    $ sudo chmod -R o-rwx /home/user/html/phpMyAdmin
  4. To upgrade to a newer version simply download the new version and extract it to the same folder. Files created by the user will remain the same, e.g. apache.conf, config.inc.php, and htpasswd.setup.
  • Note: Debian 10 dropped phpmyadmin from it's repository. Older and newer Debian versions include it.

phpMyAdmin Configuration

  1. Create the configuration file from the sample template and generate a secure blowfish secret for cookie encryption:
    sudo cp /home/user/html/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php
  2. Generate a 32-character random string using OpenSSL:
    openssl rand -base64 24 > secret
  3. Open /home/user/html/phpmyadmin/config.inc.php and paste the generated string into the $cfg['blowfish_secret'] line:
    $cfg['blowfish_secret'] = 'YOUR_GENERATED_STRING_HERE';
  4. Add custom settings:
    $cfg['FirstLevelNavigationItems'] = 150;		// number of databases in navigation, default: 100
    $cfg['MaxNavigationItems'] = 150;			// number of tables in db navigation, default: 50
    $cfg['NavigationWidth'] = 300;				// width of the navigation window, default: 240
    $cfg['RetainQueryBox'] = true;				// retain query box, results of query shown below box, default: false
    $cfg['ShowPhpInfo'] = true;				// show phpinfo link on home screen, default: false
    $cfg['TempDir'] = '/home/user/html/phpMyAdmin/tmp';	// you may omit this line as the default is ./tmp
  5. You may check phpMyAdmin’s documentation for other settings to add
  6. Leave the commented out settings in config.inc.php unchanged. The pma settings are better done within phpMyAdmin, where you click “Find out why” in the warning at the bottom of the screen when you first run phpMyAdmin, and then create the database phpmyadmin which will contain those settings.

apache2 Configuration

  1. Create /etc/apache2/conf-available/phpmyadmin.conf:
    # phpMyAdmin default Apache configuration
    
    Alias /phpmyadmin /home/user/html/phpMyAdmin
    
    # Secure access to phpMyAdmin by restricting access to it's parent, for example by IP address or domain name, local or external
    <Directory /home/user/html>
        <RequireAny>
            Require all denied
            Require ip 127.0.0.1
        </RequireAny>
    </Directory>
    
    <Directory /home/user/html/phpMyAdmin>
        Options SymLinksIfOwnerMatch
        DirectoryIndex index.php
    
        <IfModule mod_php.c>
            <IfModule mod_mime.c>
                AddType application/x-httpd-php .php
            </IfModule>
            <FilesMatch ".+\.php$">
                SetHandler application/x-httpd-php
            </FilesMatch>
    
            php_value include_path .
            php_admin_value upload_tmp_dir /home/user/html/phpMyAdmin/tmp
    	php_admin_value open_basedir /home/user/html/phpMyAdmin/:/usr/share/
        </IfModule>
    
    </Directory>
    
    # Authorize for setup
    <Directory /home/user/html/phpMyAdmin/setup>
        <IfModule mod_authz_core.c>
            <IfModule mod_authn_file.c>
                AuthType Basic
                AuthName "phpMyAdmin Setup"
                AuthUserFile /home/user/html/phpMyAdmin/htpasswd.setup
            </IfModule>
            Require valid-user
        </IfModule>
    </Directory>
    
    # Disallow web access to directories that don't need it
    <Directory /home/user/html/phpMyAdmin/templates>
        Require all denied
    </Directory>
    <Directory /home/user/html/phpMyAdmin/libraries>
        Require all denied
    </Directory>
    <Directory /home/user/html/phpMyAdmin/setup/lib>
        Require all denied
    </Directory>
  2. Enable the configuration and restart apache:
    $ sudo a2enconf phpmyadmin
    $ sudo systemctl restart apache2
  3. Create a regular MariaDB user for the purpose of managing databases through phpMyAdmin, if you haven't done that yet when configuring MariaDB. You would create a user that has privileges to all tables within the database, as well as the power to add, change, and remove user privileges, with this command. Whatever privileges you assign to this user, be sure to give it a strong password as well:
    $ sudo mariadb
    MariaDB [(none)]> CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
    MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'user'@'hostname';
    MariaDB [(none)]> FLUSH PRIVILEGES;
    MariaDB [(none)]> exit
  4. Make sure permissions are set to traverse directories, particularly /home/user/html/ and /home/user/www/

Run phpMyAdmin

  1. Access phpMyAdmin by appending /phpmyadmin to any website url hosted on the same server.
  2. You will get a warning Configuration storage has not been setup. Click link Find out why.
  3. Now click Setup configuration storage.