Advertisement
Guest User

Untitled

a guest
Dec 26th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. VHOST_CONF=/etc/apache2/sites-available/
  4. ROOT_UID=0
  5. NOTROOT=87
  6. WWW_ROOT=/var/www/
  7.  
  8. # owner of the site directory
  9. WEBUSER=www-data
  10.  
  11. # check if is root
  12. if [ "$UID" -ne "$ROOT_UID" ]
  13. then
  14. echo "You must be root to run this script."
  15. exit $NOTROOT
  16. fi
  17.  
  18. if [ -n "$1" ]
  19. then
  20. DOMAIN=$1
  21. else
  22. echo "You must provide a full domain name for this site, i.e. ‘example.com’ "
  23. echo -n "Run this script like ./a2createsite example.com"
  24. exit
  25. fi
  26.  
  27. # create document root site folder
  28. su $WEBUSER -c "mkdir -p ${WWW_ROOT}$DOMAIN/public_html"
  29.  
  30. # vhost file content
  31. # rewrite mod must be enabled
  32. CONF="<VirtualHost *:80>\n\n\tServerName $DOMAIN\n\tServerAlias www.$DOMAIN\n\tDocumentRoot ${WWW_ROOT}$DOMAIN/public_html\n\n\t<Directory ${WWW_ROOT}$DOMAIN/public_html>\n\t\tOrder Deny,Allow\n\t\tAllow from all\n\t\tOptions -Indexes\n\t</Directory>\n\n</VirtualHost>"
  33.  
  34. # write the vhost config file
  35. echo -e $CONF > ${VHOST_CONF}$DOMAIN
  36.  
  37. # enable site configuration
  38. cd $VHOST_CONF
  39. a2ensite $DOMAIN > /dev/null
  40.  
  41. echo "$DOMAIN was created. In 5 seconds your apache will be reloaded"
  42. sleep 5
  43.  
  44. /etc/init.d/apache2 reload
  45.  
  46. echo "Done"
  47. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement