Created
May 14, 2018 12:26
-
-
Save landsman/38d6204e3f46608b00a80db60efd8cb4 to your computer and use it in GitHub Desktop.
ubuntu virtualhost quick scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "Enter the VirtualHost name : " | |
| read name | |
| echo "Enter the VirtualHost root [/var/www/html/] : " | |
| read root | |
| if [ -d "/var/www/html/"$root ] | |
| then | |
| if [ -w /etc/hosts ] | |
| echo "creating apache virtial host..." | |
| then | |
| # todo: check already existing site | |
| if [ -w /etc/apache2/sites-available ] | |
| then | |
| printf "<VirtualHost *:80> | |
| ServerAdmin webmaster@localhost | |
| DocumentRoot /var/www/html/$root | |
| ServerName www.$name.dev | |
| ServerAlias $name.dev | |
| ErrorLog ${APACHE_LOG_DIR}/error.log | |
| CustomLog ${APACHE_LOG_DIR}/access.log combined | |
| </VirtualHost>" >> /etc/apache2/sites-available/$name.conf | |
| echo "adding site to hosts file..." | |
| printf "127.0.0.1 $name.dev\n" >> /etc/hosts | |
| #sudo a2enmod | |
| sudo a2ensite "$name.conf" | |
| echo "restarting apache..." | |
| sudo service apache2 restart | |
| #google-chrome "http://$name.dev" | |
| else | |
| echo "You do not have pemission to write to the apache folder , try using sudo." | |
| fi | |
| else | |
| echo "You do not have pemission to write to the $root folder , try using sudo." | |
| fi | |
| else | |
| echo "Directory $root does not exist!" | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "Enter the VirtualHost name : " | |
| read name | |
| echo "Enter the VirtualHost root [/var/www/html/] : " | |
| read root | |
| if [ -d "/var/www/html/"$root ] | |
| then | |
| if [ -w /etc/hosts ] | |
| echo "deleting apache virtial host..." | |
| then | |
| if [ -w /etc/apache2/sites-available ] | |
| then | |
| rm /etc/apache2/sites-available/$name.conf | |
| echo "removing site from hosts file..." | |
| sed -i '/127.0.0.1 $name.dev\n/d' /etc/hosts | |
| echo "restarting apache..." | |
| sudo a2dissite "$name.conf" | |
| sudo service apache2 restart | |
| else | |
| echo "You do not have pemission to write to the apache folder , try using sudo." | |
| fi | |
| else | |
| echo "You do not have pemission to write to the $root folder , try using sudo." | |
| fi | |
| else | |
| echo "Directory $root does not exist!" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment