403Webshell
Server IP : 138.197.107.151  /  Your IP : 216.73.217.10
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux BloxBy-Builder 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64
User : wpbetasites_mrakzqskir ( 1022)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/bloxbycommands/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/bloxbycommands/remove_domain.sh
#!/bin/bash
# ======================================================
# remove_domain.sh
# Remove an attached domain from an existing WP site
# ======================================================

# Usage: ./remove_domain.sh domain.com tempdomain.com webroot

REMOVE_DOMAIN=$1
TEMP_DOMAIN=$2
WEB_ROOT=$3

APACHE_CONF_DIR="/etc/apache2/sites-available"
CLEAN_DOMAIN=${REMOVE_DOMAIN#www.}
VHOST_FILE="$APACHE_CONF_DIR/$CLEAN_DOMAIN.conf"
SSL_VHOST_FILE="$APACHE_CONF_DIR/${CLEAN_DOMAIN}-le-ssl.conf"
WP_PATH="$WEB_ROOT"

if [ -z "$REMOVE_DOMAIN" ] || [ -z "$TEMP_DOMAIN" ] || [ -z "$WEB_ROOT" ]; then
  echo "❌ Error: Domain, temporary domain, and webroot are required."
  echo "Usage: $0 domain.com tempdomain.com /var/www/html"
  exit 1
fi

echo "🚨 Removing domain: $CLEAN_DOMAIN"

# Disable standard vhost
if [ -f "$VHOST_FILE" ]; then
  echo "🔧 Disabling Apache vhost..."
  a2dissite "$(basename "$VHOST_FILE")"
  rm -f "$VHOST_FILE"
else
  echo "⚠️ Vhost file not found: $VHOST_FILE"
fi

# Disable SSL vhost
if [ -f "$SSL_VHOST_FILE" ]; then
  echo "🔧 Disabling Apache SSL vhost..."
  a2dissite "$(basename "$SSL_VHOST_FILE")"
  rm -f "$SSL_VHOST_FILE"
else
  echo "⚠️ SSL vhost file not found: $SSL_VHOST_FILE"
fi

# Reload Apache to apply changes
systemctl reload apache2

# Remove SSL cert
echo "🗑️ Removing SSL certificate for $CLEAN_DOMAIN..."
certbot delete --cert-name "$CLEAN_DOMAIN" -n

# Revert WordPress back to temporary domain
echo "🔄 Reverting WordPress domain back to $TEMP_DOMAIN"
wp option update home "https://$TEMP_DOMAIN" --path=$WP_PATH --allow-root
wp option update siteurl "https://$TEMP_DOMAIN" --path=$WP_PATH --allow-root
wp search-replace "https://$CLEAN_DOMAIN" "https://$TEMP_DOMAIN" --all-tables --precise --path=$WP_PATH --allow-root

echo "✅ Domain $CLEAN_DOMAIN removed successfully."

Youez - 2016 - github.com/yon3zu
LinuXploit