apache快速开通虚拟主机shell

原创
2012/10/13 10:36
阅读数 208
#!/bin/bash
#建立在XAMPP基础上的开通虚拟主机脚本
#XAMPP: http://www.apachefriends.org
printf "Please enter Domin:"
read WEBDOMIN

# Check for the Domin.
if [ $WEBDOMIN ]; then
        echo "$WEBDOMIN Web createing...!"
		#网站目录名称规则:www.Doin, 具体目录根据自己情况修改
		WEBDIR="/opt/lampp/htdocs/www.$WEBDOMIN"
		if [ -d $WEBDIR ]; then
			echo "$WEBDIR directory exists!"
		else
			#如果目录不存在建立目录
			echo "Create dir $WEBDIR ..."
			mkdir $WEBDIR
			#修改目录所有都为nobody:nobody
			echo "CHOWN dir $WEBDIR ..."
			chown nobody:nobody $WEBDIR
		fi
		
		#修改apache vhost文件增加vhost
		echo "Create Vhost..."
		echo "" >>  /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "<VirtualHost *:80>" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "	ServerAdmin freeflowf@gmial.com" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "	DocumentRoot \"${WEBDIR}\"" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "	ServerName ${WEBDOMIN}" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "	ServerAlias www.${WEBDOMIN}" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "	ErrorLog \"logs/${WEBDOMIN}-error_log\"" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "	CustomLog \"logs/${WEBDOMIN}-access_log\" common" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		echo "</VirtualHost>" >> /opt/lampp/etc/extra/httpd-vhosts.conf
		
		#重启APACHE, 完成
		echo "Reload apache..."
		/opt/lampp/lampp reloadapache
		
		#开通MYSQL
		#CREATE USER 'abcc'@'%' IDENTIFIED BY  '***';
		#GRANT USAGE ON * . * TO  'abcc'@'%' IDENTIFIED BY  '***' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
		#CREATE DATABASE IF NOT EXISTS  `abcc` ;
		#GRANT ALL PRIVILEGES ON  `abcc` . * TO  'abcc'@'%';
		#mysql -e 'sql' 不用在mysql的提示符下运行mysql
		printf "Create Mysql User [y|n]:"
		read CMU
		if [[ $CMU == [yY] ]]; then
			#输入mysql用户名
			mysqlUserName=""
			while [ "$mysqlUserName" = "" ]
			do
				printf "\nEnter Mysql User Name:"
				read mysqlUserName
			done
			echo "Mysql User: $mysqlUserName"
			#输入mysql密码
			mysqlUserPass=""
			while [ "$mysqlUserPass" = "" ]
			do
				printf "\nEnter Mysql User Password:"
				read mysqlUserPass
			done
			echo "Mysql Password: $mysqlUserPass"
			#执行语句添加帐户和表
			mysqlHost="localhost" #Mysql主机地址
			mysqlRoot="root" #Mysql管理员用户
			mysqlPass="***" #Mysql管理员密码
			/opt/lampp/bin/mysql -h${mysqlHost} -u${mysqlRoot} -p${mysqlPass} -e "CREATE USER '${mysqlUserName}'@'%' IDENTIFIED BY  '${mysqlUserPass}'"
			/opt/lampp/bin/mysql -h${mysqlHost} -u${mysqlRoot} -p${mysqlPass} -e "GRANT USAGE ON * . * TO  '${mysqlUserName}'@'%' IDENTIFIED BY  '${mysqlUserPass}' WITH MAX_QUERIES_PER_HOUR 100 MAX_CONNECTIONS_PER_HOUR 100 MAX_UPDATES_PER_HOUR 100 MAX_USER_CONNECTIONS 100"
			/opt/lampp/bin/mysql -h${mysqlHost} -u${mysqlRoot} -p${mysqlPass} -e "CREATE DATABASE IF NOT EXISTS  ${mysqlUserName}"
			/opt/lampp/bin/mysql -h${mysqlHost} -u${mysqlRoot} -p${mysqlPass} -e "GRANT ALL PRIVILEGES ON  ${mysqlUserName} . * TO  '${mysqlUserName}'@'%'"
		fi
		
else
		echo "Domin is empty. Please try agin!"
fi

展开阅读全文
打赏
0
5 收藏
分享
加载中
更多评论
打赏
0 评论
5 收藏
0
分享
返回顶部
顶部