Apache Virtual Host Yaradıcı
Apache üçün yeni virtual host yaradan, konfiqurasiya edən və aktivləşdirən avtomatik script.
Yayımlanma: 05.04.2024
Kod
#!/bin/bash
# Apache Virtual Host Creator
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
read -p "Enter domain name: " DOMAIN
read -p "Enter document root (default: /var/www/$DOMAIN): " DOCROOT
DOCROOT=${DOCROOT:-/var/www/$DOMAIN}
mkdir -p "$DOCROOT"
chown -R www-data:www-data "$DOCROOT"
cat > "/etc/apache2/sites-available/${DOMAIN}.conf" << EOF
<VirtualHost *:80>
ServerName $DOMAIN
ServerAlias www.$DOMAIN
DocumentRoot $DOCROOT
<Directory $DOCROOT>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog \${APACHE_LOG_DIR}/${DOMAIN}-error.log
CustomLog \${APACHE_LOG_DIR}/${DOMAIN}-access.log combined
</VirtualHost>
EOF
# Create index file
cat > "$DOCROOT/index.html" << EOF
<!DOCTYPE html>
<html>
<head>
<title>Welcome to $DOMAIN</title>
</head>
<body>
<h1>$DOMAIN is working!</h1>
</body>
</html>
EOF
a2ensite "${DOMAIN}.conf"
systemctl reload apache2
echo "✓ Virtual host created successfully!"
echo "Document root: $DOCROOT"
echo ""
echo "Add to /etc/hosts for local testing:"
echo "127.0.0.1 $DOMAIN"
İstifadə
sudo chmod +x create_vhost.sh
sudo ./create_vhost.sh
# Enter domain name
# Specify document root (optional)