#!/bin/bash set -e echo "===== [1] Starting package installation =====" apt-get update apt-get install -y apache2 php mariadb-server php-mysql php-curl curl wget sleep 5 echo "===== [2] Moving to web directory =====" cd /var/www/html echo "===== [3] Downloading AI Lab package =====" wget -O ncp-ai-lab.tgz https://kr.object.ncloudstorage.com/ncp-manual/ncpai/ncp-ai-lab.tgz sleep 3 echo "===== [4] Extracting package =====" tar xvfz ncp-ai-lab.tgz sleep 3 echo "===== [5] Applying Apache configuration =====" if [ -f phpadd ]; then cat phpadd >> /etc/apache2/apache2.conf elif [ -f /mnt/data/phpadd ]; then cat /mnt/data/phpadd >> /etc/apache2/apache2.conf else echo "WARNING: phpadd file not found. Skipping..." fi sleep 2 echo "===== [6] Validating Apache configuration =====" apache2ctl -t echo "===== [7] Enabling and restarting services =====" systemctl enable apache2 systemctl enable mariadb systemctl restart mariadb sleep 5 systemctl restart apache2 sleep 5 echo "===== [8] Waiting for Apache to become active =====" until systemctl is-active --quiet apache2; do echo "Waiting for Apache to start..." sleep 2 done echo "===== [9] Checking Apache status =====" systemctl status apache2 --no-pager || true echo "===== [10] Checking Apache processes =====" ps -ef | grep apache2 || true echo "===== [11] Checking port 80 =====" ss -ntlp | grep :80 || true echo "===== [12] Final Apache configuration check =====" apache2ctl -t echo "===== DONE ====="