Advertisement
thephpx

bash-apache-virtual-host

Mar 3rd, 2016
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. #!/bin/bash
  2. #asks password so that it can go and perform action in root directories
  3. su
  4. echo "Please give the domain name :"
  5. read domain
  6.  
  7. echo "Please give the IP address :"
  8. read ipaddrs
  9.  
  10. if [ -d "/etc" ]; then
  11.   if [ -d "/etc/apache2" ]; then
  12.     if [ -d "/etc/apache2/sites-available" ]; then
  13.    
  14.         if [ -f "/etc/apache2/sites-available/"$domain".conf" ]; then
  15.            
  16.             echo "SITE ALREADY EXISTS"
  17.            
  18.         else
  19.             echo "CREATE NEW SITE CONFIG FILE"
  20.            
  21.             cd "/etc/apache2/sites-available"
  22.             touch $domain".conf"
  23.            
  24.            
  25.             echo "CREATE ENTRY INSIDE THE SITE CONFIG FILE"
  26.            
  27.             echo "<VirtualHost *:80>" >> $domain".conf"
  28.             echo '\t DocumentRoot "/home/'$domain'/public"' >> $domain".conf"
  29.             echo "\t ServerName "$domain  >> $1".conf"
  30.             echo "\t ServerAlias www."$domain >> $1".conf"
  31.            
  32.             echo '\t <Directory "/home/'$domain'/public">' >> $domain".conf"
  33.                 echo '\t\t allow from all' >> $domain".conf"
  34.                 echo '\t\t order allow,deny' >> $domain".conf"
  35.                 echo '\t\t AllowOverride All' >> $domain".conf"
  36.             echo '\t </Directory>' >> $domain".conf"
  37.            
  38.             echo "</VirtualHost>"  >> $domain".conf"
  39.            
  40.             echo "CREATE HOST FILE ENTRY"
  41.             cd "../../"
  42.             echo $ipaddrs $domain >> hosts
  43.            
  44.             cd "../home"
  45.             echo "CREATE HOME DIRECTORY"
  46.             mkdir $domain
  47.             cd $domain
  48.             mkdir "public"
  49.             cd "public"
  50.             touch index.html
  51.             echo "Welcome to "$domain >> index.html
  52.  
  53.             echo "HOST SETUP SUCCESSFULLY. PLEASE RESTART APACHE."
  54.         fi
  55.     else
  56.         echo "ERROR: '/etc/apache2/sites-available' does not exists";
  57.     fi
  58.   fi
  59. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement