Skip to content

Instantly share code, notes, and snippets.

@dmpop
Last active December 15, 2023 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmpop/84d1de22f4c3afd965f730316c955afb to your computer and use it in GitHub Desktop.
Save dmpop/84d1de22f4c3afd965f730316c955afb to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
echo "-----------------------------------------"
echo " Enter a domain name (example: hello.xyz)"
echo " Press ENTER"
echo "-----------------------------------------"
echo
read domain_name
touch /etc/apache2/sites-available/$domain_name.conf
echo "<VirtualHost *:80>" > /etc/apache2/sites-available/$domain_name.conf
echo "" >> /etc/apache2/sites-available/$domain_name.conf
echo "DocumentRoot /var/www/html/$domain_name" >> /etc/apache2/sites-available/$domain_name.conf
echo "ServerName $domain_name" >> /etc/apache2/sites-available/$domain_name.conf
echo "ServerAlias $domain_name" >> /etc/apache2/sites-available/$domain_name.conf
echo "" >> /etc/apache2/sites-available/$domain_name.conf
echo "<Directory /var/www/html/$domain_name/>" >> /etc/apache2/sites-available/$domain_name.conf
echo "Options FollowSymlinks" >> /etc/apache2/sites-available/$domain_name.conf
echo "AllowOverride All" >> /etc/apache2/sites-available/$domain_name.conf
echo "Require all granted" >> /etc/apache2/sites-available/$domain_name.conf
echo "</Directory>" >> /etc/apache2/sites-available/$domain_name.conf
echo "" >> /etc/apache2/sites-available/$domain_name.conf
echo 'ErrorLog ${APACHE_LOG_DIR}/error.log' >> /etc/apache2/sites-available/$domain_name.conf
echo 'CustomLog ${APACHE_LOG_DIR}/access.log combined' >> /etc/apache2/sites-available/$domain_name.conf
echo "" >> /etc/apache2/sites-available/$domain_name.conf
echo "</VirtualHost>" >> /etc/apache2/sites-available/$domain_name.conf
sudo a2dissite 000-default
sudo a2ensite $domain_name.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
sudo certbot --apache
sudo mkdir /var/www/html/$domain_name
sudo chown www-data:www-data -R /var/www/html/$domain_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment