When I create new web applications on my up-2-date Ubuntu-LAMP with Apache 2.4.x environment, I create their virtual-host files this way:
s_a="/etc/apache2/sites-available/"
s_e="/etc/apache2/sites-enabled/"
read -p "Have you created db credentials already?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please create db credentials in then comeback;";;
esac
read -p "Please enter the domain of your web application:" domain_1 && echo
read -p "Please enter the domain of your web application again:" domain_2 && echo
if [ "$domain_1" != "$domain_2" ]; then echo "Values unmatched. Please try again." && exit 2; fi
read -sp "Please enter the app DB root password:" dbrootp_1 && echo
read -sp "Please enter the app DB root password again:" dbrootp_2 && echo
if [ "$dbrootp_1" != "$dbrootp_2" ]; then echo "Values unmatched. Please try again." && exit 2; fi
read -sp "Please enter the app DB user password:" dbuserp_1 && echo
read -sp "Please enter the app DB user password again:" dbuserp_2 && echo
if [ "$dbuserp_1" != "$dbuserp_2" ]; then echo "Values unmatched. Please try again." && exit 2; fi
cat <<-EOF > "$s_a/$domain_2.conf"
<VirtualHost *:80>
ServerAdmin admin@"$domain_2"
ServerName ${domain_2}
ServerAlias www.${domain_2}
DocumentRoot /var/www/html/${domain_2}
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
ln -sf "$s_a"/"$domain_2".conf "$s_e"
My question
Is there a way to automate that / shorten the amount of lines code (the actual script-file is much bigger in principle), maybe even from some built-in behavior in Apache itself and without involving further software?
If other software might be needed than from what I've read so far it should be Docker and I should look for an Apache-virtual host docker script that will be based on my variable declarations (in dockerhub) which I will then run with a docker command, but maybe Apache itself will have automation functionality for this or there is some third solution the answer's my need?