Skip to content

Instantly share code, notes, and snippets.

@trungpv1601
Created March 28, 2020 09:31
Show Gist options
  • Save trungpv1601/5170caa42b8b61814d799c14766e28e9 to your computer and use it in GitHub Desktop.
Save trungpv1601/5170caa42b8b61814d799c14766e28e9 to your computer and use it in GitHub Desktop.
Setup a new site apache2 on Ubuntu

Run

sudo chmod 777 new-site.sh
./new-site.sh
#!/usr/bin/env bash
#encoding=utf8
# Main
function main() {
echo "-------------------------"
echo "Add new site Apache2"
echo "-------------------------"
echo "Please enter few infomation for a new site: "
read -p "Domain: " domain
read -p "Email: " email
sudo mkdir "/var/www/$domain"
sudo chown -R www-data:www-data "/var/www/$domain"
sudo chmod -R 755 "/var/www/$domain"
cat > "/var/www/$domain/_i.php" <<EOF
<?php
phpinfo();
EOF
cat > "/etc/apache2/sites-available/$domain.conf" <<EOF
<VirtualHost *:80>
ServerAdmin $email
ServerName $domain
ServerAlias www.$domain
DocumentRoot /var/www/$domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/$domain>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
EOF
sudo a2ensite "$domain.conf"
sudo a2enmod rewrite
sudo systemctl restart apache2
echo "-------------------------"
echo "DONE ;)"
echo "Your Website: http://$domain"
echo "-------------------------"
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment