This is a simple script to setup a vdir and folder for Apache on Ubuntu:

 

First make a template file for the Apache config

First:

nano /etc/apache2/sites-available/template.conf

<VirtualHost *:80>

    ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.

    ServerName newsite

    ServerAlias newsite

    DocumentRoot /var/www/newsite/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

#save the above

 

 

Second:

nano createweb.sh

 echo "Setting up website: $1"

 sitename=$1

 sudo mkdir /var/www/$1

 sudo mkdir /var/www/$1/public_html

 sudo chown -R ubuntu:ubuntu /var/www/$1/public_html

 sudo cp /etc/apache2/sites-available/template.conf /etc/apache2/sites-available/$1.conf

 sed -i "s/newsite/$sitename/g" /etc/apache2/sites-available/$sitename.conf

 sudo a2ensite $sitename.conf

 sudo chown -R www-data:www-data /var/www

 sudo service apache2 restart

 

 

Third:

Now give accesss to run

chmod +x createweb.sh

 

Fourth:

Now test it:

./createweb.sh mylamesite.com