Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- domain=$1
- # Only run if sudo or root
- if [ "$(whoami)" != 'root' ]; then
- echo -e $"You don't have permission to run $0 as non-root user. \nUse sudo"
- exit 1;
- fi
- # Get user input:
- while [ "$domain" == "" ]
- do
- echo -e $"Provide a domain. e.g. domain.dev or Ctrl+c to quit."
- read domain
- done
- # Set the path to the document root
- documentRoot='/var/www/'$domain'/public_html'
- # Make the directory
- mkdir -p $documentRoot
- # Set permissions
- chown -R $USER:$USER $documentRoot
- # Write this to Apache's sites-available.conf
- echo "
- <VirtualHost *:80>
- ServerName $domain
- ServerAlias www.$domain
- ServerAdmin webmaster@localhost
- DocumentRoot $documentRoot
- #LogLevel info ssl:warn
- ErrorLog \${APACHE_LOG_DIR}/error.log
- #CustomLog \${APACHE_LOG_DIR}/access.log combined
- #Include conf-available/serve-cgi-bin.conf
- <Directory $documentRoot >
- Options Indexes FollowSymLinks MultiViews
- # AllowOverride All allows using .htaccess
- AllowOverride All
- Order allow,deny
- allow from all
- </Directory>
- </VirtualHost>
- " > '/etc/apache2/sites-available/'$domain'.conf'
- # a2ensite, a2dissite - enable or disable an apache2 site / virtual host
- a2ensite $domain'.conf'
- # Append your domain to /etc/hosts
- echo -e "127.0.0.1\t"$domain >> /etc/hosts
- # Restart apache
- service apache2 restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement