Posted By

theriddlebrothers on 02/16/11


Tagged

apache vhost


Versions (?)

Virtual Hosts Creator


 / Published in: Bash
 

Add an Apache virtual host via command line. Run as ./create mysite.domain.com

  1. #!/bin/bash
  2. VHOST_CONF=/etc/httpd/conf/httpd-vhosts.conf
  3. ROOT_UID=0
  4. E_NOTROOT=87
  5. WWW_ROOT=/var/www/vhosts
  6.  
  7. # Run as root
  8. if [ "$UID" -ne "$ROOT_UID" ]
  9. then
  10. echo "Must be root to run this script."
  11. exit $E_NOTROOT
  12. fi
  13.  
  14. if [ -n "$1" ]
  15. # Test whether command line present
  16. then
  17. DOMAIN=$1
  18. else
  19. echo "You must provide a full domain name for this site, i.e. 'mysite.domain.net'."
  20. exit
  21. fi
  22.  
  23. # create site folder
  24. mkdir $WWW_ROOT/$DOMAIN
  25. mkdir $WWW_ROOT/$DOMAIN/public_html
  26. chown riddleftp:ftp-users $WWW_ROOT/$DOMAIN -R
  27.  
  28. CONF=""
  29. #echo $CONF >> $VHOST_CONF
  30.  
  31. CONF="\n\n##################\n# $DOMAIN\n##################\n<VirtualHost *:80>\n DocumentRoot \"$WWW_ROOT/$DOMAIN/public_html\"\n ServerName $DOMAIN\n</VirtualHost>\n"
  32. echo -e $CONF >> $VHOST_CONF
  33.  
  34. apachectl restart

Report this snippet  

You need to login to post a comment.