Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. domain=$1
  4.  
  5.  
  6. # Only run if sudo or root
  7. if [ "$(whoami)" != 'root' ]; then
  8. echo -e $"You don't have permission to run $0 as non-root user. \nUse sudo"
  9. exit 1;
  10. fi
  11.  
  12.  
  13. # Get user input:
  14. while [ "$domain" == "" ]
  15. do
  16. echo -e $"Provide a domain. e.g. domain.dev or Ctrl+c to quit."
  17. read domain
  18. done
  19.  
  20.  
  21. # Set the path to the document root
  22. documentRoot='/var/www/'$domain'/public_html'
  23.  
  24.  
  25. # Make the directory
  26. mkdir -p $documentRoot
  27.  
  28.  
  29. # Set permissions
  30. chown -R $USER:$USER $documentRoot
  31.  
  32.  
  33. # Write this to Apache's sites-available.conf
  34. echo "
  35. <VirtualHost *:80>
  36.  
  37. ServerName $domain
  38. ServerAlias www.$domain
  39. ServerAdmin webmaster@localhost
  40. DocumentRoot $documentRoot
  41.  
  42. #LogLevel info ssl:warn
  43.  
  44. ErrorLog \${APACHE_LOG_DIR}/error.log
  45. #CustomLog \${APACHE_LOG_DIR}/access.log combined
  46.  
  47. #Include conf-available/serve-cgi-bin.conf
  48.  
  49. <Directory $documentRoot >
  50. Options Indexes FollowSymLinks MultiViews
  51. # AllowOverride All allows using .htaccess
  52. AllowOverride All
  53. Order allow,deny
  54. allow from all
  55. </Directory>
  56.  
  57. </VirtualHost>
  58. " > '/etc/apache2/sites-available/'$domain'.conf'
  59.  
  60.  
  61. # a2ensite, a2dissite - enable or disable an apache2 site / virtual host
  62. a2ensite $domain'.conf'
  63.  
  64.  
  65. # Append your domain to /etc/hosts
  66. echo -e "127.0.0.1\t"$domain >> /etc/hosts
  67.  
  68.  
  69. # Restart apache
  70. service apache2 restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement