Pages

Add vhost using script

Adding vhost on apache it's very annoying, you have to add it line by line. so, why not just simplify. so, i try using script.

login to your server. create new file called siteup

sidiq:~ # touch siteup 

insert this line to siteup :




=========================================================================================== 
#!  /bin/bash 
# 
# ======================= 
# Siteup Script 0.1 
#  Written by Command Line Idiot 
# http://commandlineidiot.com 
# You  may use, modify, and redistribute this script freely 
# Released:  August 2007 
# ======================= 

#  ======================= 
#       set functions 
#  ======================= 
#       make_index is the function to create a  basic index.html file 
#       within the documents directory of the  new domain. The variable 
#       for domain name is passed into the  file at $dname. You can alter 
#       any of the code between the  terms _EOF_ and it will be reflected 
#       in the index.html file. 

function  make_index 
{ 
cat <<- _EOF_


welcome to $dname 

_EOF_ 
} 

#        make_vhost is the function to create a config file that 
#        Apache2 can interpret. The variable for the domain name is passed 
#        into the file at $dname, and the system-wide variable for username 
#        is passed into the file at $USER. You may wish to replace the 
#        ServerAdmin email address with your own email address. You may alter 
#        any of the code between the terms _EOF_ to build your own preferred 
#        standard config file. 

function make_vhost 
{ 
cat <<-  _EOF_
 

ServerAdmin $USER@localhost 

ServerName $dname 

ServerAlias www.$dname 



DirectoryIndex index.html  index.htm index.php 

DocumentRoot  /home/$USER/$dname/htdocs 



ScriptAlias /cgi-bin/  /home/$USER/$dname/cgi-bin/ 

 

Options +ExecCGI 

 



 

Options Indexes FollowSymLinks MultiViews 

AllowOverride All 

Order allow,deny 

Allow from all 

 



ErrorLog /home/$USER/logs/$dname/error.log 

CustomLog  /home/$USER/logs/$dname/access.log combined 

 
_EOF_ 
} 

# ======================= 
#             header 
# ======================= 
clear 
echo "***      Site  Setup      ***" 

# ======================= 
# set domain name  variable 
# ======================= 
echo -n "==> Enter user name  for this vhost : " 
read USER 
echo -n "==> Enter new domain  name (domain.com): " 
read dname 
echo "Setting up files for $dname" 

#  ======================= 
# create needed directories 
#  ======================= 
mkdir -vp /home/$USER/$dname/htdocs 
mkdir  -vp /home/$USER/$dname/cgi-bin 
mkdir -vp /home/$USER/logs/$dname 
touch  /home/$USER/logs/$dname/access.log 
echo "created  /home/$USER/logs/$dname/access.log" 
touch  /home/$USER/logs/$dname/error.log 
echo "created  /home/$USER/logs/$dname/error.log" 

# ======================= 
#  build index.html file 
# ======================= 
make_index >  /home/$USER/$dname/htdocs/index.html 
echo "created  /home/$USER/$dname/htdocs/index.html" 

#======================= 
#change  directory owner to users 
#====================== 
chown -R  $USER.users /home/$USER 


# ======================= 
# build  vhost config file 
# ======================= 
#make_vhost >  /home/$USER/www-config/sites-available/$dname 
#echo "created  /home/$USER/www-config/sites-available/$dname" 
make_vhost >>  /usr/local/apache2/conf/extra/httpd-vhosts.conf 
echo "added new line  to /usr/local/apache2/conf/extra/httpd-vhost.conf" 

#  ======================= 
#    exit 
# ======================= 

echo  "***      Finished setting up files for $dname. Goodbye!" 
exit 

================================================================================== 

change permission siteup

sidiq:~ # chmod 755 siteup 

now, test it out

sidiq:~ # ./siteup 

No comments:

Post a Comment