Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Completes an unattend installation of MySQL with phpMyAdmin.
#!/bin/bash
#
# Author: Edwin Velez
# Author URI: edwinvelez.net
# Description: Completes an unattend installation of MySQL with phpMyAdmin.
MYSQL_HOST=“localhost”
MYSQL_PASSWORD="Password"
PHPMYADMIN_APP_PASSWORD="Password"
PHPMYADMIN_MYSQL_PASSWORD="Password"
# Update package index and upgrade existing packages
apt-get update
apt-get upgrade -y
# Install Debconf
apt-get install -y debconf-utils
# Disable prompts during installations
export DEBIAN_FRONTEND="noninteractive"
# Example Debconf usage to get selections: debconf-get-selections | grep mysql
#
# MySQL Server
debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_PASSWORD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD"
# phpMyAdmin
debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"
debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean false"
debconf-set-selections <<< "phpmyadmin phpmyadmin/internal/skip-preseed boolean true"
# Download and install necessary packages
install_os_packages() {
apt-get install -y mysql-server phpmyadmin
}
# Secure mySql Installation
# See Assigning Anonymous Account Passwords (https://dev.mysql.com/doc/refman/5.7/en/default-privileges.html)
secure_mysql_installation() {
# Remove anonymous logins.
`mysql -u root "-pPassword" mysql --execute="DROP USER ''@'localhost';"`
# Disallow root login remotely.
`mysql -u root "-pPassword" mysql --execute="DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"`
# Remove test database and access to it.
`mysql -u root "-pPassword" mysql --execute="DELETE FROM mysql.db WHERE Db LIKE 'test%';"`
`mysql -u root "-pPassword" mysql --execute="DROP DATABASE test;"`
}
install_os_packages
secure_mysql_installation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.