public
Created

Add New Website in CentOS

  • Download Gist
website.sh
Shell
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/bin/bash
 
HTMLPATH="/var/www/html"
VHOSTPATH="/etc/httpd/conf.d"
LOGPATH="/var/log/httpd"
BITBUCKETUSERNAME="username"
 
if [ $1 = "add" ]; then
 
# Create html dir
if [ ! -d $HTMLPATH/$2 ]; then
mkdir $HTMLPATH/$2
cd $HTMLPATH/$2
git init
git remote add origin ssh://git@bitbucket.org/$BITBUCKETUSERNAME/$2.git
git pull origin master
else
echo "Error: $HTMLPATH/$2 directory doesn't exists."
exit
fi
 
# Create logs files
if [ ! -d $LOGPATH/$2 ]; then
mkdir $LOGPATH/$2
touch $LOGPATH/$2/access_log
touch $LOGPATH/$2/error_log
else
echo "Error: $LOGPATH/$2 directory doesn't exists."
exit
fi
# Create the virtual host conf file
if [ ! -f $VHOSTPATH/$2.conf ]; then
echo -e "<VirtualHost *:80>\nServerAdmin root@$2\nDocumentRoot /var/www/html/$2\nServerName $2\nServerAlias www.$2\nCustomLog $LOGPATH/$2/access_log common\nErrorLog $LOGPATH/$2/error_log\n</VirtualHost>" > $VHOSTPATH/$2.conf
else
echo "Error: $VHOSTPATH/$2.conf file doesn't exists."
exit
fi
fi
 
if [ $1 = "remove" ]; then
read -ep "Are you sure you want to delete $2 ? " -n 1 -r
if [[ $REPLY =~ ^[YySs]$ ]]; then
if [ -d $HTMLPATH/$2 ]; then
rm -rf $HTMLPATH/$2
fi
if [ -d $LOGPATH/$2 ]; then
rm -rf $LOGPATH/$2
fi
if [ -f $VHOSTPATH/$2.conf ]; then
rm $VHOSTPATH/$2.conf
fi
else
exit
fi
fi
 
# Restart apache
/etc/init.d/httpd restart
/etc/init.d/mysqld restart

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.