#!/bin/bash # ============================================================================== # Script Name: systron-wp-deploy.sh # Description: Automated LEMP + Redis Deployer for 1GB+ WordPress Databases # Target: Systron Cloud SSD VPS (Ubuntu, Debian, AlmaLinux, Rocky Linux) # ============================================================================== # Ensure script is run as root if [ "$EUID" -ne 0 ]; then echo "❌ Error: Please run this script as root or using sudo." exit 1 fi # Clear screen and show banner clear echo "=====================================================================" echo " 🚀 Systron VPS WordPress & High-Performance DB Setup Utility 🚀 " echo "=====================================================================" echo "" # ------------------------------------------------------------------------------ # Step 1: Environment & Architecture Detection # ------------------------------------------------------------------------------ echo "🔍 Detecting OS Distribution and Server Resources..." # Detect Linux Flavor if [ -f /etc/os-release ]; then . /etc/os-release OS_FLAVOR=$ID OS_VERSION=$VERSION_ID else echo "❌ Error: Cannot determine operating system flavor. Exiting." exit 1 fi # Detect Server RAM to calculate buffer pools dynamically TOTAL_RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}') TOTAL_RAM_MB=$((TOTAL_RAM_KB / 1024)) echo " -> Operating System: ${OS_FLAVOR^} (Version: $OS_VERSION)" echo " -> Total System RAM: ${TOTAL_RAM_MB} MB" # Dynamically calculate ideal MariaDB InnoDB Buffer Pool Size (55% of total RAM) BUFFER_POOL_MB=$((TOTAL_RAM_MB * 55 / 100)) # Ensure buffer pool has at least 1 instance per GB BUFFER_POOL_INSTANCES=$((BUFFER_POOL_MB / 1024)) if [ "$BUFFER_POOL_INSTANCES" -lt 1 ]; then BUFFER_POOL_INSTANCES=1; fi echo " -> Calculated DB Optimization Buffer Pool: ${BUFFER_POOL_MB} MB" echo "" # ------------------------------------------------------------------------------ # Step 2: Distribution-Specific Dependency Installation # ------------------------------------------------------------------------------ echo "📦 Installing LEMP Stack components for ${OS_FLAVOR^}..." case "$OS_FLAVOR" in ubuntu|debian) export DEBIAN_FRONTEND=noninteractive apt-get update -y apt-get install -y curl wget nginx mariadb-server mariadb-client redis-server php-fpm php-mysql php-redis php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip unzip # Identify PHP version installed to locate correct config paths PHP_VER=$(php -r 'print PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;') PHP_INI_PATH="/etc/php/$PHP_VER/fpm/php.ini" PHP_FPM_POOL="/etc/php/$PHP_VER/fpm/pool.d/www.conf" MYSQL_CONF="/etc/mysql/mariadb.conf.d/50-server.cnf" [ ! -f "$MYSQL_CONF" ] && MYSQL_CONF="/etc/mysql/my.cnf" ;; rocky|almalinux|rhel) # Enable EPEL and REMI repositories for up-to-date PHP packages dnf install -y epel-release dnf install -y https://remirepo.net(echo $OS_VERSION | cut -d. -f1).rpm dnf module reset php -y dnf module enable php:remi-8.2 -y # Defaulting to stable PHP 8.2 # Install packages dnf install -y nginx mariadb-server mariadb redis php php-fpm php-mysqlnd php-pecl-redis5 php-curl php-gd php-mbstring php-xml php-soap php-intl php-pecl-zip unzip PHP_INI_PATH="/etc/php.ini" PHP_FPM_POOL="/etc/php-fpm.d/www.conf" MYSQL_CONF="/etc/my.cnf.d/mariadb-server.cnf" [ ! -f "$MYSQL_CONF" ] && MYSQL_CONF="/etc/my.cnf" # Open basic firewall ports if systemctl is-active --quiet firewalld; then firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https firewall-cmd --reload fi ;; *) echo "❌ Error: Flavor '$OS_FLAVOR' is not supported by this automation script." exit 1 ;; esac echo "✅ Package installation complete." echo "" # ------------------------------------------------------------------------------ # Step 3: Injecting High-Performance Configurations # ------------------------------------------------------------------------------ echo "⚙️ Injecting resource optimizations for 1GB+ WordPress databases..." # 1. Optimize Database Configurations if [ -f "$MYSQL_CONF" ]; then cp "$MYSQL_CONF" "${MYSQL_CONF}.bak" # Safely append configuration parameters directly under the [mysqld] block cat <> "$MYSQL_CONF" # --- Systron NVMe Database Engine Optimizations --- [mysqld] innodb_buffer_pool_size = ${BUFFER_POOL_MB}M innodb_buffer_pool_instances = ${BUFFER_POOL_INSTANCES} innodb_log_file_size = 512M innodb_log_buffer_size = 16M innodb_flush_log_at_trx_commit = 2 innodb_flush_method = O_DIRECT innodb_file_per_table = 1 max_connections = 150 tmp_table_size = 64M max_heap_table_size = 64M join_buffer_size = 4M EOF echo " [+] Database configurations optimized successfully." else echo " [⚠️] Warning: Could not locate MySQL/MariaDB configuration file path." fi # 2. Optimize PHP Engine Limits if [ -f "$PHP_INI_PATH" ]; then cp "$PHP_INI_PATH" "${PHP_INI_PATH}.bak" sed -i "s/memory_limit =.*/memory_limit = 512M/" "$PHP_INI_PATH" sed -i "s/upload_max_filesize =.*/upload_max_filesize = 128M/" "$PHP_INI_PATH" sed -i "s/post_max_size =.*/post_max_size = 128M/" "$PHP_INI_PATH" sed -i "s/max_execution_time =.*/max_execution_time = 300/" "$PHP_INI_PATH" echo " [+] PHP-FPM Engine limits scaled up." fi # 3. Configure Redis Storage Optimization REDIS_CONF="/etc/redis/redis.conf" [ ! -f "$REDIS_CONF" ] && REDIS_CONF="/etc/redis.conf" if [ -f "$REDIS_CONF" ]; then cp "$REDIS_CONF" "${REDIS_CONF}.bak" # Ensure background updates don't cause performance memory warnings echo "maxmemory 256mb" >> "$REDIS_CONF" echo "maxmemory-policy allkeys-lru" >> "$REDIS_CONF" echo " [+] Memory-efficient Redis configurations injected." fi echo "" # ------------------------------------------------------------------------------ # Step 4: System Restart & Verification # ------------------------------------------------------------------------------ echo "🔄 Starting and enabling application services..." # Define service names based on architecture NGINX_SVC="nginx" MARIADB_SVC="mariadb" REDIS_SVC="redis-server" [ "$OS_FLAVOR" = "rocky" ] || [ "$OS_FLAVOR" = "almalinux" ] && REDIS_SVC="redis" case "$OS_FLAVOR" in ubuntu|debian) PHP_SVC="php$PHP_VER-fpm" ;; rocky|almalinux|rhel) PHP_SVC="php-fpm" ;; esac # Enable and restart all core stack structures for service in $NGINX_SVC $MARIADB_SVC $REDIS_SVC $PHP_SVC; do systemctl daemon-reload systemctl enable $service >/dev/null 2>&1 systemctl restart $service if systemctl is-active --quiet $service; then echo " [✔] Service execution confirmed: $service" else echo " [❌] Service failure alert: $service failed to transition up." fi done echo "" echo "=====================================================================" echo "🎉 SUCCESS: Your Systron Cloud VPS Stack is Ready for Action! 🎉" echo "=====================================================================" echo " • Nginx is running and ready for Virtual Host files." echo " • MariaDB buffer mapping dynamically scales to: ${BUFFER_POOL_MB}MB RAM." echo " • Redis Caching engine is listening for WordPress Object hooks." echo "=====================================================================" echo "Next step: Point your domain to this server IP and run your WP migration!"