#!/bin/bash # Ensure the script runs with root privileges if [ "$(id -u)" -ne 0 ]; then echo "This script must be run as root" 1>&2 exit 1 fi # Update package list and install necessary packages apt-get update -y apt-get install -y apache2 mysql-server php libapache2-mod-php php-mysqli php-json php-common php-mbstring php-zip php-xml php-gd php-curl php-bz2 php-ldap php-imagick # Automatically select Apache2 during phpMyAdmin installation (without user intervention) echo "phpmyadmin phpmyadmin/webserver select apache2" | debconf-set-selections # Install phpMyAdmin (with no user interaction) DEBIAN_FRONTEND=noninteractive apt-get install -y phpmyadmin # Generate a random password for phpMyAdmin user phpmyadmin_password=$(openssl rand -base64 12) # Set the MySQL root password (if not already set) mysql_root_password=$(openssl rand -base64 12) # Set MySQL root password if not already set echo "Setting MySQL root password" mysqladmin -u root password "$mysql_root_password" # Check if the phpmyadmin user already exists and drop it if it does echo "Checking if phpMyAdmin user exists" existing_user=$(mysql -u root -p"$mysql_root_password" -e "SELECT COUNT(*) FROM mysql.user WHERE User = 'phpmyadmin';" | tail -n 1) if [ "$existing_user" -gt 0 ]; then echo "Dropping existing phpMyAdmin user" mysql -u root -p"$mysql_root_password" -e "DROP USER IF EXISTS 'phpmyadmin'@'localhost';" fi # Create phpMyAdmin user with mysql_native_password plugin echo "Creating phpMyAdmin user" mysql -u root -p"$mysql_root_password" -e "CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY '$phpmyadmin_password';" # Grant privileges to phpMyAdmin user echo "Granting privileges to phpMyAdmin user" mysql -u root -p"$mysql_root_password" -e "GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'phpmyadmin'@'localhost';" mysql -u root -p"$mysql_root_password" -e "FLUSH PRIVILEGES;" # Link phpMyAdmin to Apache's web directory (optional) # ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin # Uncomment if necessary # Configure Apache to automatically restart and reconfigure echo "Reconfiguring Apache to apply changes" a2enmod rewrite # Enable PHP module (adjust according to PHP version installed) a2enmod php7.4 # Adjust according to the PHP version installed (e.g., php7.4, php8.0) # Restart Apache to apply changes service apache2 restart cp /home/tibia/1mindeploy/phpmyadmin.conf /etc/apache2/conf-available a2enconf phpmyadmin # Output phpMyAdmin password and MySQL root password for user reference #echo "phpMyAdmin user created with the following password: $phpmyadmin_password" echo "MySQL root password: $mysql_root_password" # Clean up and remove unnecessary packages #apt-get clean