-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualhost.sh
32 lines (30 loc) · 1017 Bytes
/
virtualhost.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
#apache virtual host
#usage : ./virtualhost.sh domainname
#must have apache2
#sudo apt-get install apache2
echo "Create Apache Virtual Host"
echo "Usage : chmod +x virtualhost.sh"
echo "./virtualhost.sh domainname"
echo "Enjoy !!! @gitnepal"
sudo mkdir -p /var/www/$1/
sudo chown -R $USER:$USER /var/www/$1/
sudo chmod -R 755 /var/www
echo "It works!" >> /var/www/$1/index.html
echo -e "\e[1;31m Submit the form: \e[0m"
read -p "ServerAdmin eg- [email protected] : " ServerAdmin
read -p "ServerAlias eg- www.demo.com : " ServerAlias
sudo chmod -R 777 /etc/apache2/sites-available/
sudo echo "<VirtualHost *:80>
ServerAdmin $ServerAdmin
ServerName $1
ServerAlias $ServerAlias
DocumentRoot /var/www/$1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>" >> /etc/apache2/sites-available/$1.conf
sudo a2ensite $1.conf
sudo service apache2 reload
sudo chmod -R 777 /etc/hosts
echo "127.0.0.1 $1" >> /etc/hosts
sudo service apache2 reload