This is a short script I put together that allows for easy creation of Apache Virtual Host along with a new attached user.
#!/bin/bash
echo “Enter Username:”
read username
echo “Enter URL:”
read url
useradd -s /usr/lib/sftp-server -U -md /var/www/$url $username
password=$(date +%s | sha256sum | base64 | head -c 15)
echo ”
<VirtualHost *:80>
ServerAdmin $user@$url
ServerName $url
ServerAlias www.$url
DocumentRoot /var/www/$url/public_html
ErrorLog /var/www/$url/error.log
CustomLog /var/www/$url/access.log combined
</VirtualHost>” > /etc/apache2/sites-available/$url.conf
a2ensite /etc/apache2/sites-available/$url.conf
service apache2 reload
chown -R $username:$username /var/www/$url
chmod -R 755 /var/www/$url
echo “Password $password”