Skip to content

Instantly share code, notes, and snippets.

@teledirigido
Created August 2, 2014 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save teledirigido/bb76d7c5eea988af527e to your computer and use it in GitHub Desktop.
Save teledirigido/bb76d7c5eea988af527e to your computer and use it in GitHub Desktop.
Add new website via Bash script. Working with Ubuntu server.
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "You must be a root user" 2>&1
exit 1
fi
echo "<VirtualHost *:80>
ServerAdmin admin@example.co.nz
ServerName $1
ServerAlias www.$1
DocumentRoot /var/www/$1/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" > /etc/apache2/sites-available/$1.conf
sudo a2ensite $1
service apache2 restart
mkdir /var/www/$1
mkdir /var/www/$1/public_html/
chown -R www-data:www-data /var/www/$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment