From 2378485d1954a0d390b8b44f2e7b7a26b2ac949f Mon Sep 17 00:00:00 2001 From: fadmin Date: Sat, 13 Jun 2026 10:51:14 -0400 Subject: [PATCH] Add install_lamp.sh --- install_lamp.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 install_lamp.sh diff --git a/install_lamp.sh b/install_lamp.sh new file mode 100644 index 0000000..c725a9d --- /dev/null +++ b/install_lamp.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +# Check for root privileges +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root (use sudo)" + exit 1 +fi + +# 1. Prompt for the MySQL Root Password +echo "Enter the desired MySQL root password:" +read -s SECURE_PASS +echo "Confirm the MySQL root password:" +read -s SECURE_PASS_CONFIRM + +if [ "$SECURE_PASS" != "$SECURE_PASS_CONFIRM" ]; then + echo "Passwords do not match. Exiting." + exit 1 +fi + +# 2. Add repository for PHP 8.2 (Ondrej Sury PPA / Repository) +echo "Setting up PHP 8.2 repository..." +apt update -y +apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 + +if [ -f /etc/debian_version ]; then + # Pure Debian setup + curl -sS https://packages.sury.org/php/README.txt | bash +else + # Ubuntu setup + add-apt-repository ppa:ondrej/php -y +fi + +apt update -y + +# 3. Install Packages (Apache, MariaDB, PHP 8.2 + Extensions, phpMyAdmin) +# We pre-seed the phpMyAdmin choice so it installs completely unattended +echo "phpmyadmin phpmyadmin/reconfigure-webconfig select apache2" | debconf-set-selections +echo "phpmyadmin phpmyadmin/dbconfig-install boolean false" | debconf-set-selections + +apt install -y apache2 mariadb-server php8.2 php8.2-mysql php8.2-mbstring \ +php8.2-gd php8.2-xml php8.2-zip php8.2-curl php8.2-imap php8.2-apcu phpmyadmin + +# 4. Start Services +systemctl enable --now apache2 +systemctl enable --now mariadb + +# 5. Set MySQL Root Password +# Debian uses mysql_native_password or unix_socket by default. We alter root to use native passwords for tools like phpMyAdmin. +sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('$SECURE_PASS');" +sudo mysql -e "FLUSH PRIVILEGES;" + +# 6. Configure phpMyAdmin for Remote Access +# Debian puts the phpmyadmin configuration into its own file. We link it to Apache. +if [ -f /etc/phpmyadmin/apache.conf ]; then + ln -sf /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf + a2enconf phpmyadmin > /dev/null +fi + +# 7. Firewall (UFW on Debian/Ubuntu instead of firewalld) +if command -v ufw &> /dev/null; then + ufw allow 'Apache Full' +fi + +# 8. Restart Apache +systemctl restart apache2 + +echo "------------------------------------------------" +echo "LAMP Installation Complete!" +echo "PHP Version: $(php -v | head -n 1)" +echo "Extensions: IMAP, APCu" +echo "URL: http://$(curl -s https://ifconfig.me)/phpmyadmin" +echo "------------------------------------------------" + +# 9. CALL THE NEXT SCRIPT +NEXT_SCRIPT="./manage_vhosts.sh" +if [ -f "$NEXT_SCRIPT" ]; then + echo "Found $NEXT_SCRIPT. Launching post-install setup..." + chmod +x "$NEXT_SCRIPT" + "$NEXT_SCRIPT" +else + echo "No follow-up script found at $NEXT_SCRIPT. Finished." +fi \ No newline at end of file