Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. SITE_NAME=$1
  4. SITE_CONFIG_PATH=/etc/apache2/sites-available/$SITE_NAME.conf
  5. SSL_SITE_CONFIG_PATH=/etc/apache2/sites-available/$SITE_NAME-ssl.conf
  6.  
  7. echo "Setting up virtual hosts..."
  8.  
  9. cd /etc/apache2/sites-available/
  10.  
  11. VIRTUAL_HOST="<VirtualHost *:80>
  12. ServerName $SITE_NAME.test
  13. ServerAdmin webmaster@$SITE_NAME.test
  14. DocumentRoot /home/jonathan/development/websites/$SITE_NAME
  15. <Directory \"/home/jonathan/development/websites/$SITE_NAME\">
  16. #Require local
  17. Order allow,deny
  18. Allow from all
  19. AllowOverride all
  20. # New directive needed in Apache 2.4.3:
  21. Require all granted
  22. </Directory>
  23. ErrorLog \${APACHE_LOG_DIR}/$SITE_NAME-error.log
  24. CustomLog \${APACHE_LOG_DIR}/$SITE_NAME-access.log combined
  25. </VirtualHost>"
  26.  
  27. echo "$VIRTUAL_HOST" | sudo tee -a $SITE_CONFIG_PATH
  28.  
  29. SSL_VIRTUAL_HOST="<IfModule mod_ssl.c>
  30. <VirtualHost _default_:443>
  31. ServerAdmin webmaster@$SITE_NAME.test
  32.  
  33. DocumentRoot /home/jonathan/development/websites/$SITE_NAME
  34.  
  35. <Directory \"/home/jonathan/development/websites/$SITE_NAME\">
  36. #Require local
  37. Order allow,deny
  38. Allow from all
  39. AllowOverride all
  40. # New directive needed in Apache 2.4.3:
  41. Require all granted
  42. </Directory>
  43.  
  44. ErrorLog \${APACHE_LOG_DIR}/$SITE_NAME-error.log
  45. CustomLog \${APACHE_LOG_DIR}/$SITE_NAME-access.log combined
  46.  
  47. SSLEngine on
  48.  
  49. SSLCertificateFile /home/jonathan/ssl-certs/$SITE_NAME.test.pem
  50. SSLCertificateKeyFile /home/jonathan/ssl-certs/$SITE_NAME.test-key.pem
  51.  
  52. <FilesMatch \"\.(cgi|shtml|phtml|php)\$\">
  53. SSLOptions +StdEnvVars
  54. </FilesMatch>
  55. <Directory /usr/lib/cgi-bin>
  56. SSLOptions +StdEnvVars
  57. </Directory>
  58.  
  59. </VirtualHost>
  60. </IfModule>"
  61.  
  62. echo "$SSL_VIRTUAL_HOST" | sudo tee -a $SSL_SITE_CONFIG_PATH
  63.  
  64. echo "Enabling virtual hosts..."
  65.  
  66. a2ensite $SITE_NAME.conf
  67. a2ensite $SITE_NAME-ssl.conf
  68.  
  69. echo "Setting up certs..."
  70.  
  71. cd ~/ssl-certs/
  72.  
  73. #todo figure out how to either run this as me, or run the other stuff as sudo, without a password
  74. mkcert $SITE_NAME.test
  75.  
  76. echo "Add hosts record.."
  77.  
  78. echo "127.0.0.1 $SITE_NAME.test" >> /etc/hosts
  79.  
  80. echo "Restarting Apache..."
  81.  
  82. sudo service apache2 restart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement