Anons79 Mini Shell

Directory : /home/aplikasiposinfo/www/langganan.fixmate.id/
Upload File :
Current File : /home/aplikasiposinfo/www/langganan.fixmate.id/create_vhost.sh

#!/bin/bash

# Exit immediately if a command exits with a non-zero status.
set -e

# Check for arguments
if [ -z "$1" ] || [ -z "$2" ]; then
    echo "Usage: $0 <domain_name> <log_file_path>"
    exit 1
fi


DOMAIN=$1
LOG_FILE=$2
CONF_FILE="/etc/apache2/conf.d/$DOMAIN.conf"
ADMIN_EMAIL="[email protected]"
WEB_ROOT_BASE="/home/aplikasiposinfo/public_html"

# Use a function for logging to avoid repetition
log() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}



# Create Apache config file
log "Step 1: Creating directory and temporary VHost..."
echo "--- Creating Apache config file ---"
cat > "$CONF_FILE" <<EOF
<VirtualHost 202.157.184.142:80>
  ServerName $DOMAIN
    ServerAlias www.$DOMAIN
  DocumentRoot $WEB_ROOT_BASE/$DOMAIN/public
  ServerAdmin webmaster@$DOMAIN
  UseCanonicalName Off

  ## User aplikasiposinfo # Needed for Cpanel::ApacheConf
  <IfModule userdir_module>
    <IfModule !mpm_itk.c>
      <IfModule !ruid2_module>
        <IfModule !mod_passenger.c>
          UserDir disabled
          UserDir enabled aplikasiposinfo 
        </IfModule>
      </IfModule>
    </IfModule>
  </IfModule>

  # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
  # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
  # the user's .htaccess file.  For more information, please read:
  #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
  <IfModule include_module>
    <Directory "$WEB_ROOT_BASE/$DOMAIN/public">
      SSILegacyExprParser On
    </Directory>
  </IfModule>

  ErrorLog /home/aplikasiposinfo/logs/error_$DOMAIN.log
  CustomLog /home/aplikasiposinfo/logs/access_$DOMAIN.log combined

  

  <IfModule suphp_module>
    suPHP_UserGroup aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule suexec_module>
    <IfModule !mod_ruid2.c>
      SuexecUserGroup aplikasiposinfo aplikasiposinfo
    </IfModule>
  </IfModule>
  <IfModule ruid2_module>
    RMode config
    RUidGid aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mpm_itk.c>
    # For more information on MPM ITK, please read:
    #   http://mpm-itk.sesse.net/
    AssignUserID aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mod_passenger.c>
    PassengerUser aplikasiposinfo
    PassengerGroup aplikasiposinfo
  </IfModule>

  <IfModule alias_module>
    ScriptAlias /cgi-bin/ $WEB_ROOT_BASE/$DOMAIN/public/cgi-bin/
  </IfModule>


    # Global DCV Rewrite Exclude
    <IfModule rewrite_module>
        RewriteOptions Inherit
    </IfModule>

    <IfModule proxy_fcgi_module>
        <FilesMatch \.(phtml|php[0-9]*)$>
            SetHandler proxy:unix:/opt/cpanel/ea-php82/root/usr/var/run/php-fpm/84e6845b84696394c9dfc5123bad0b0f35cefd53.sock|fcgi://$DOMAIN
        </FilesMatch>
    </IfModule>


  # To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/std/2_4/aplikasiposinfo/$DOMAIN/*.conf"
</VirtualHost>


<VirtualHost 202.157.184.142:443>
  ServerName $DOMAIN
  ServerAlias www.$DOMAIN
  DocumentRoot $WEB_ROOT_BASE/$DOMAIN/public
  ServerAdmin webmaster@$DOMAIN
  UseCanonicalName Off

  ## User aplikasiposinfo # Needed for Cpanel::ApacheConf
  <IfModule userdir_module>
    <IfModule !mpm_itk.c>
      <IfModule !ruid2_module>
        <IfModule !mod_passenger.c>
          UserDir disabled
          UserDir enabled aplikasiposinfo 
        </IfModule>
      </IfModule>
    </IfModule>
  </IfModule>

  # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
  # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
  # the user's .htaccess file.  For more information, please read:
  #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
  <IfModule mod_include.c>
    <Directory "$WEB_ROOT_BASE/$DOMAIN/public">
      SSILegacyExprParser On
    </Directory>
  </IfModule>

  ErrorLog /home/aplikasiposinfo/logs/error_$DOMAIN.log
  CustomLog /home/aplikasiposinfo/logs/access_$DOMAIN.log combined

  
  <Proxymatch ^https?://127\.0\.0\.1:(2082|2083|2077|2078|2079|2080|2086|2087|2095|2096)/>
       <IfModule security2_module>
          SecRuleEngine Off
       </IfModule>
       <IfModule security3_module>
          modsecurity_rules 'SecRuleEngine Off'
       </IfModule>
  </Proxymatch>

  <IfModule mod_suphp.c>
    suPHP_UserGroup aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule suexec_module>
    <IfModule !mod_ruid2.c>
      SuexecUserGroup aplikasiposinfo aplikasiposinfo
    </IfModule>
  </IfModule>
  <IfModule ruid2_module>
    RMode config
    RUidGid aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mpm_itk.c>
    # For more information on MPM ITK, please read:
    #   http://mpm-itk.sesse.net/
    AssignUserID aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mod_passenger.c>
    PassengerUser aplikasiposinfo
    PassengerGroup aplikasiposinfo
  </IfModule>

  <IfModule alias_module>
    ScriptAlias /cgi-bin/ $WEB_ROOT_BASE/$DOMAIN/public/cgi-bin/
  </IfModule>

    <IfModule proxy_fcgi_module>
        <FilesMatch \.(phtml|php[0-9]*)$>
            SetHandler proxy:unix:/opt/cpanel/ea-php82/root/usr/var/run/php-fpm/52a81bb01baa45c94940102ee00ab13d765db972.sock|fcgi://$DOMAIN
        </FilesMatch>
    </IfModule>

    # <IfModule ssl_module>
    #     SSLEngine on
    #     SSLCertificateFile /etc/letsencrypt/live/$DOMAIN/fullchain.pem
    #     SSLCertificateKeyFile /etc/letsencrypt/live/$DOMAIN/privkey.pem

    #     SSLUseStapling off
    #     <Directory "$WEB_ROOT_BASE/$DOMAIN/public/cgi-bin">
    #         SSLOptions +StdEnvVars
    #     </Directory>
    # </IfModule>




  # To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/ssl/2_4/aplikasiposinfo/$DOMAIN/*.conf"

</VirtualHost>
EOF

sleep 2

# restart Apache
echo "--- restarting Apache ---"
systemctl restart httpd

log "Waiting 5 seconds for server to reload..."
sleep 5

### Step 2: 🔒 Obtain the SSL Certificate using Certbot.
log "Step 2: Obtaining SSL certificate with Certbot..."
echo "--- Step 2: Obtaining SSL Certificate with Certbot ---"
certbot certonly --webroot -w "$WEB_ROOT_BASE/$DOMAIN/public" -d "$DOMAIN" --email "$ADMIN_EMAIL" --agree-tos --non-interactive


### Step 3: 📝 Update the virtual host to use HTTPS.
echo "--- Step 3: Updating VHost configuration for HTTPS ---"
# Overwrite the configuration file with the final HTTPS version
cat > "$CONF_FILE" <<EOF
<VirtualHost 202.157.184.142:80>
  ServerName $DOMAIN
    ServerAlias www.$DOMAIN
  DocumentRoot $WEB_ROOT_BASE/$DOMAIN/public
  ServerAdmin webmaster@$DOMAIN
  UseCanonicalName Off

  ## User aplikasiposinfo # Needed for Cpanel::ApacheConf
  <IfModule userdir_module>
    <IfModule !mpm_itk.c>
      <IfModule !ruid2_module>
        <IfModule !mod_passenger.c>
          UserDir disabled
          UserDir enabled aplikasiposinfo 
        </IfModule>
      </IfModule>
    </IfModule>
  </IfModule>

  # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
  # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
  # the user's .htaccess file.  For more information, please read:
  #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
  <IfModule include_module>
    <Directory "$WEB_ROOT_BASE/$DOMAIN/public">
      SSILegacyExprParser On
    </Directory>
  </IfModule>

  

  <IfModule suphp_module>
    suPHP_UserGroup aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule suexec_module>
    <IfModule !mod_ruid2.c>
      SuexecUserGroup aplikasiposinfo aplikasiposinfo
    </IfModule>
  </IfModule>
  <IfModule ruid2_module>
    RMode config
    RUidGid aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mpm_itk.c>
    # For more information on MPM ITK, please read:
    #   http://mpm-itk.sesse.net/
    AssignUserID aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mod_passenger.c>
    PassengerUser aplikasiposinfo
    PassengerGroup aplikasiposinfo
  </IfModule>

  <IfModule alias_module>
    ScriptAlias /cgi-bin/ $WEB_ROOT_BASE/$DOMAIN/public/cgi-bin/
  </IfModule>


    # Global DCV Rewrite Exclude
    <IfModule rewrite_module>
        RewriteOptions Inherit
    </IfModule>

    <IfModule proxy_fcgi_module>
        <FilesMatch \.(phtml|php[0-9]*)$>
            SetHandler proxy:unix:/opt/cpanel/ea-php82/root/usr/var/run/php-fpm/84e6845b84696394c9dfc5123bad0b0f35cefd53.sock|fcgi://$DOMAIN
        </FilesMatch>
    </IfModule>


  # To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/std/2_4/aplikasiposinfo/$DOMAIN/*.conf"
</VirtualHost>


<VirtualHost 202.157.184.142:443>
  ServerName $DOMAIN
  ServerAlias www.$DOMAIN
  DocumentRoot $WEB_ROOT_BASE/$DOMAIN/public
  ServerAdmin webmaster@$DOMAIN
  UseCanonicalName Off

  ## User aplikasiposinfo # Needed for Cpanel::ApacheConf
  <IfModule userdir_module>
    <IfModule !mpm_itk.c>
      <IfModule !ruid2_module>
        <IfModule !mod_passenger.c>
          UserDir disabled
          UserDir enabled aplikasiposinfo 
        </IfModule>
      </IfModule>
    </IfModule>
  </IfModule>

  # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
  # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
  # the user's .htaccess file.  For more information, please read:
  #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
  <IfModule mod_include.c>
    <Directory "$WEB_ROOT_BASE/$DOMAIN/public">
      SSILegacyExprParser On
    </Directory>
  </IfModule>

  
  <Proxymatch ^https?://127\.0\.0\.1:(2082|2083|2077|2078|2079|2080|2086|2087|2095|2096)/>
       <IfModule security2_module>
          SecRuleEngine Off
       </IfModule>
       <IfModule security3_module>
          modsecurity_rules 'SecRuleEngine Off'
       </IfModule>
  </Proxymatch>

  <IfModule mod_suphp.c>
    suPHP_UserGroup aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule suexec_module>
    <IfModule !mod_ruid2.c>
      SuexecUserGroup aplikasiposinfo aplikasiposinfo
    </IfModule>
  </IfModule>
  <IfModule ruid2_module>
    RMode config
    RUidGid aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mpm_itk.c>
    # For more information on MPM ITK, please read:
    #   http://mpm-itk.sesse.net/
    AssignUserID aplikasiposinfo aplikasiposinfo
  </IfModule>
  <IfModule mod_passenger.c>
    PassengerUser aplikasiposinfo
    PassengerGroup aplikasiposinfo
  </IfModule>

  <IfModule alias_module>
    ScriptAlias /cgi-bin/ $WEB_ROOT_BASE/$DOMAIN/public/cgi-bin/
  </IfModule>

    <IfModule proxy_fcgi_module>
        <FilesMatch \.(phtml|php[0-9]*)$>
            SetHandler proxy:unix:/opt/cpanel/ea-php82/root/usr/var/run/php-fpm/52a81bb01baa45c94940102ee00ab13d765db972.sock|fcgi://$DOMAIN
        </FilesMatch>
    </IfModule>

    <IfModule ssl_module>
        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/$DOMAIN/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/$DOMAIN/privkey.pem

        SSLUseStapling off
        <Directory "$WEB_ROOT_BASE/$DOMAIN/public/cgi-bin">
            SSLOptions +StdEnvVars
        </Directory>
    </IfModule>




  # To customize this VirtualHost use an include file at the following location
  # Include "/etc/apache2/conf.d/userdata/ssl/2_4/aplikasiposinfo/$DOMAIN/*.conf"

</VirtualHost>
EOF

# run php artisan
echo "--- run artisan ---"
log "Step 4: Generate Key & Clear Cache..."
php /home/aplikasiposinfo/public_html/$DOMAIN/artisan key:generate
php /home/aplikasiposinfo/public_html/$DOMAIN/artisan optimize:clear
log "Step 5: Migrating and seeding the database..."
php /home/aplikasiposinfo/public_html/$DOMAIN/artisan migrate
php /home/aplikasiposinfo/public_html/$DOMAIN/artisan db:seed

# restart Apache
log "Step 6: Updating VHost configuration for HTTPS..."
echo "--- restarting Apache ---"
systemctl restart httpd

echo "--- Virtual host for $DOMAIN created successfully! ---"
log "--- SCRIPT_COMPLETE ---"

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]