Created
February 23, 2024 16:18
-
-
Save dimatall/c59c35df27b9f3af22e55916f925218d to your computer and use it in GitHub Desktop.
Scan www directory and create new vhost based on folders in /var/www
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 | |
sortdomains=~/dont_remove.txt | |
vhostfile=/etc/apache2/sites-available | |
echo "Append domains to sort file."; | |
find /var/www -mindepth 1 -maxdepth 1 -type d -printf '%f\n' >> $sortdomains | |
echo "Loop"; | |
for domain in `sort $sortdomains | uniq -u`; | |
do | |
echo "Create vhost for $domain"; | |
cat <<- EOF > "/etc/apache2/sites-available/$domain.conf" | |
<VirtualHost *:80> | |
ServerAdmin admin@$domain | |
ServerName $domain | |
ServerAlias www.$domain | |
DocumentRoot /var/www/$domain/public_html | |
<Directory /var/www/$domain/public_html> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride All | |
Require all granted | |
</Directory> | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
</VirtualHost> | |
EOF | |
/usr/sbin/a2ensite $domain | |
done | |
systemctl reload apache2 | |
echo "Clean up sort file."; | |
find /var/www -mindepth 1 -maxdepth 1 -type d -printf '%f\n' > $sortdomains | |
echo "Done."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment