You are here: Home / Debian GNU/Linux / Web applications / Administration / Install PHPMyAdmin on Debian

Install PHPMyAdmin on Debian

by Pierre-Yves Landuré last modified Nov 11, 2017 09:29

PHPMyAdmin is a Web application easing MySQL server administration. This howto helps its install on Debian.

This howto is tested on :

  • Debian 6.0 Squeeze
  • Debian 7.0 Wheezy
  • Ubuntu 10.04 Lucid Lynx
  • Ubuntu 10.10 Natty Narwal

Prerequisites

This howto needs :

Installation

Install the software :

command apt-get install phpmyadmin php5-mcrypt php5-gd

The tool is now available at: http://localhost/phpmyadmin/

Manual setup

Note : the following commands are useless (and harmless) if the PHPMyAdmin automatic setup has been used.

Detect the path of the script creating the database used by the software to manage various informations:

SCRIPT="/usr/share/doc/phpmyadmin/scripts/create_tables_mysql_4_1_2+.sql.gz"
if [ -e "/usr/share/doc/phpmyadmin/examples/create_tables_mysql_4_1_2+.sql.gz" ]; then
  SCRIPT="/usr/share/doc/phpmyadmin/examples/create_tables_mysql_4_1_2+.sql.gz"
fi
if [ -e "/usr/share/doc/phpmyadmin/examples/create_tables.sql.gz" ]; then
  SCRIPT="/usr/share/doc/phpmyadmin/examples/create_tables.sql.gz"
fi
SQL_COMMAND=$(command gunzip --to-stdout "${SCRIPT}")

Create the pma database and its user:

if [ ! -e "/etc/dbconfig-common/phpmyadmin.conf" ]; then
  MYSQL_PASSWD="$(command apg -q -a  0 -n 1 -M NCL)"
  echo "${SQL_COMMAND};
GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY '${MYSQL_PASSWD}';;
GRANT SELECT (
    Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
    Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,
    File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,
    Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,
    Execute_priv, Repl_slave_priv, Repl_client_priv
    ) ON mysql.user TO 'pma'@'localhost';
GRANT SELECT ON mysql.db TO 'pma'@'localhost';
GRANT SELECT ON mysql.host TO 'pma'@'localhost';
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
    ON mysql.tables_priv TO 'pma'@'localhost';" \
    | command mysql --user=root --password
fi

Setup the software to use the database:

if [ ! -e "/etc/dbconfig-common/phpmyadmin.conf" ]; then
  command sed -i -e "s|[/]*\(.*pmadb.*=\)[^;]*\(;.*\)$|\1 'phpmyadmin'\2|" \
            -e "s|[/]*\(.*controluser.*=\)[^;]*\(;.*\)$|\1 'pma'\2|" \
            -e "s|[/]*\(.*controlpass.*=\)[^;]*\(;.*\)$|\1 '$MYSQL_PASSWD'\2|" \
            -e "s|[/]*\(.*auth_type.*=\)[^;]*\(;.*\)$|\1 'cookie'\2|" \
            -e "s|[/]*\(.*pma_.*;.*\)$|\1|" \
        "/etc/phpmyadmin/config.inc.php"
fi

Note: If needed, "force" the URL used to access the software. Add this line at the end of '/etc/phpmyadmin/config.inc.php' file (adjust the bolded value to your setup):

$cfg['PmaAbsoluteUri'] = 'http://www.mon-domaine.com/un-chemin/phpmyadmin/';

Thanks