Last active
August 7, 2025 17:53
-
-
Save sohelrana820/58e92dd5c7541975670e58e796800b9f to your computer and use it in GitHub Desktop.
Setup GIT, MySQL 8.0, Docker, Docker Compose, NGINX server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| # Colors for output | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' # No Color | |
| # Function to print colored output | |
| print_status() { | |
| echo -e "${BLUE}🔧 $1${NC}" | |
| } | |
| print_success() { | |
| echo -e "${GREEN}✅ $1${NC}" | |
| } | |
| print_warning() { | |
| echo -e "${YELLOW}⚠️ $1${NC}" | |
| } | |
| print_error() { | |
| echo -e "${RED}❌ $1${NC}" | |
| } | |
| # Function to check if command exists | |
| command_exists() { | |
| command -v "$1" >/dev/null 2>&1 | |
| } | |
| # Function to detect OS | |
| detect_os() { | |
| if [[ -f /etc/os-release ]]; then | |
| . /etc/os-release | |
| OS=$ID | |
| VERSION=$VERSION_ID | |
| else | |
| print_error "Cannot detect OS" | |
| exit 1 | |
| fi | |
| } | |
| # Check if running as root | |
| if [[ $EUID -eq 0 ]]; then | |
| print_error "This script should not be run as root" | |
| exit 1 | |
| fi | |
| print_status "Detecting operating system..." | |
| detect_os | |
| print_success "Detected OS: $OS $VERSION" | |
| # Verify OS compatibility | |
| if [[ "$OS" != "ubuntu" ]] && [[ "$OS" != "debian" ]]; then | |
| print_error "This script is designed for Ubuntu/Debian systems only" | |
| exit 1 | |
| fi | |
| print_status "Updating system packages..." | |
| sudo apt update && sudo apt upgrade -y | |
| print_success "System updated" | |
| print_status "Installing essential packages..." | |
| sudo apt install -y curl wget gnupg lsb-release ca-certificates software-properties-common | |
| print_success "Essential packages installed" | |
| # Install Git | |
| if command_exists git; then | |
| print_warning "Git is already installed ($(git --version))" | |
| else | |
| print_status "Installing Git..." | |
| sudo apt install -y git | |
| print_success "Git installed ($(git --version))" | |
| fi | |
| # Install MySQL 8.0 | |
| if command_exists mysql; then | |
| print_warning "MySQL is already installed" | |
| mysql --version | |
| else | |
| print_status "Installing MySQL 8.0..." | |
| # Download and install MySQL APT repository | |
| MYSQL_APT_CONFIG="mysql-apt-config_0.8.30-1_all.deb" | |
| wget -q "https://dev.mysql.com/get/${MYSQL_APT_CONFIG}" || { | |
| print_error "Failed to download MySQL APT config" | |
| exit 1 | |
| } | |
| # Install with non-interactive mode | |
| sudo DEBIAN_FRONTEND=noninteractive dpkg -i "$MYSQL_APT_CONFIG" | |
| sudo apt update | |
| # Install MySQL server with non-interactive mode | |
| sudo DEBIAN_FRONTEND=noninteractive apt install -y mysql-server | |
| # Clean up | |
| rm -f "$MYSQL_APT_CONFIG" | |
| # Enable and start MySQL service | |
| sudo systemctl enable mysql | |
| sudo systemctl start mysql | |
| print_success "MySQL installed and started" | |
| # Check MySQL status | |
| if sudo systemctl is-active --quiet mysql; then | |
| print_success "MySQL service is running" | |
| else | |
| print_error "MySQL service failed to start" | |
| exit 1 | |
| fi | |
| fi | |
| # Install Docker | |
| if command_exists docker; then | |
| print_warning "Docker is already installed ($(docker --version))" | |
| else | |
| print_status "Installing Docker..." | |
| # Remove old versions if they exist | |
| sudo apt remove -y docker docker-engine docker.io containerd runc 2>/dev/null || true | |
| # Add Docker's official GPG key | |
| sudo mkdir -p /etc/apt/keyrings | |
| curl -fsSL https://download.docker.com/linux/$OS/gpg | \ | |
| sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
| # Add Docker repository | |
| echo \ | |
| "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ | |
| https://download.docker.com/linux/$OS $(lsb_release -cs) stable" | \ | |
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
| # Update package index | |
| sudo apt update | |
| # Install Docker packages | |
| sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
| # Install standalone docker-compose for compatibility | |
| DOCKER_COMPOSE_VERSION="v2.24.5" | |
| sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
| sudo chmod +x /usr/local/bin/docker-compose | |
| # Enable and start Docker service | |
| sudo systemctl enable docker | |
| sudo systemctl start docker | |
| print_success "Docker installed" | |
| # Verify Docker installation | |
| if sudo systemctl is-active --quiet docker; then | |
| print_success "Docker service is running" | |
| docker --version | |
| docker compose version | |
| else | |
| print_error "Docker service failed to start" | |
| exit 1 | |
| fi | |
| fi | |
| # Add current user to docker group | |
| if groups "$USER" | grep -q docker; then | |
| print_warning "User $USER is already in the docker group" | |
| else | |
| print_status "Adding user $USER to docker group..." | |
| sudo usermod -aG docker "$USER" | |
| print_success "User added to docker group" | |
| print_warning "You need to logout and login again (or run 'newgrp docker') for group changes to take effect" | |
| fi | |
| # Final status check | |
| print_status "Installation complete! Checking services..." | |
| echo "" | |
| print_success "=== Installation Summary ===" | |
| if command_exists git; then | |
| echo "✅ Git: $(git --version)" | |
| fi | |
| if command_exists mysql; then | |
| echo "✅ MySQL: $(mysql --version)" | |
| if sudo systemctl is-active --quiet mysql; then | |
| echo " └── Status: Running" | |
| else | |
| echo " └── Status: Not running" | |
| fi | |
| fi | |
| if command_exists docker; then | |
| echo "✅ Docker: $(docker --version)" | |
| if command_exists docker-compose; then | |
| echo "✅ Docker Compose (standalone): $(docker-compose --version)" | |
| fi | |
| echo "✅ Docker Compose (plugin): $(docker compose version --short)" | |
| if sudo systemctl is-active --quiet docker; then | |
| echo " └── Status: Running" | |
| else | |
| echo " └── Status: Not running" | |
| fi | |
| fi | |
| echo "" | |
| print_success "Server setup completed successfully!" | |
| print_warning "Remember to logout/login or run 'newgrp docker' to use Docker without sudo" | |
| # Optional: Provide next steps | |
| echo "" | |
| print_status "Recommended next steps:" | |
| echo "1. Configure MySQL security: sudo mysql_secure_installation" | |
| echo "2. Test Docker: docker run hello-world" | |
| echo "3. Test Docker Compose: docker-compose --version" | |
| echo "4. Configure firewall if needed: sudo ufw enable" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment