Install and configure PhpMyAdmin
#!/usr/bin/env bash
# Install and configure PhpMyAdmin. This script resolves
# the two error messages displayed after installing PhpMyAdmin.
clear
echo --------------------------------------------------------
echo When prompted for password, enter root password for sudo
echo --------------------------------------------------------
echo Installing phpmyadmin
sudo apt-get -qq update
sudo apt-get -yqq install phpmyadmin apache2-utils
clear
echo --------------------------------------------------------
echo Configuring phpmyadmin
echo When prompted for password, enter root password for sudo
echo --------------------------------------------------------
CONFIG_FILE=/etc/phpmyadmin/config.inc.php
# -- start make changes to $CONFIG_FILE
# -------------------------------------
# Uncomment $cfg that start at the beginning of the line.
sudo sed -i 's/^\s*\/\/\s*\$cfg/$cfg/g' $CONFIG_FILE
# Swap out 'pma__' prefix for 'pma_'.
sudo sed -i 's/pma__/pma_/g' /etc/phpmyadmin/config.inc.php
# Change 'controluser' name
sudo sed -i "s/\(^\s*\$cfg\['Servers'\]\[\$i\]\['controluser'\]\s*=\s*\).*$/\1'pma';/" $CONFIG_FILE
# Change 'controlpass' password.
sudo sed -i "s/\(^\s*\$cfg\['Servers'\]\[\$i\]\['controlpass'\]\s*=\s*\).*$/\1'pmapassword';/" $CONFIG_FILE
# Comment out 'AllowNoPassword.'
sudo sed -i "s/^\s*\(\$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\] = TRUE;\).*$/ \/\/\1/" $CONFIG_FILE
# Comment out 'compress.'
sudo sed -i "s/^\s*\(\$cfg\['Servers'\]\[\$i\]\['compress'\] = false;\).*$/ \/\/\1/" $CONFIG_FILE
# -------------------------------------
# -- end make changes to $CONFIG_FILE
# Give 'other' read rights to blowfish_secret.inc.php.
sudo chmod 0644 /var/lib/phpmyadmin/blowfish_secret.inc.php
# Grant MySQL rights for pma user to tables in phpmyadmin.
mysql -u root -p -e 'GRANT SELECT, INSERT, DELETE, UPDATE ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY "pmapassword"'
clear
echo phpmyadmin ready to use