How to write an installation configuration httpd service domain-based virtual host script

Source: Internet
Author: User
Tags mkdir root directory

Write the installation configuration httpd service domain-based virtual host script

Requirements:

1, automatic installation, basic configuration

2, through the prompt input domain name, website root directory, and so on to complete the virtual host add work

#!/bin/bash

Service httpd Stop &>/dev/null

conf= "/usr/local/apache/conf/httpd.conf"

vhostconf= "/usr/local/apache/conf/extra/httpd-vhosts.conf"

Bin= "/usr/local/apache/bin/apachectl"

Rootdir= "/www"

Mkdir-p $rootdir

grep "Vhost" $conf | grep "#" &>/dev/null

If [$?-eq 0]; Then

vhost=$ (grep "vhost" $conf | sed "s/#//")

Sed-i '/vhost/d ' $conf &>/dev/null

echo "$vhost" >> $conf

echo "Namevirtualhost *:80" > $vhostconf

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/

echo "<directory $rootdir >

Order Allow,deny

Allow from all

</Directory> ">> $vhostconf

Fi

While True

Todo

Read-p "hostname of FDQN:" FDQN

Read-p "Directory of website:" SiteDir

Mkdir-p $rootdir/$sitedir/html

Mkdir-p $rootdir/$sitedir/logs

domain=$ (echo $fdqn | awk-f. ' {print $. ') $} ')

echo "<virtualhost *:80>

ServerAdmin admin@ $domain

DocumentRoot $rootdir/$sitedir/html

ServerName $FDQN

ErrorLog $rootdir/$sitedir/logs/error_log

Customlog $rootdir/$sitedir/logs/access_log Common

</VirtualHost> ">> $vhostconf

Read-p "continue to do"? (yes/no) "yn

if [$yn = no];then

$bin Start &>/dev/null

Exit 0

Fi

Done

This article is from the "Soldier" blog, please be sure to keep this source http://ganbing.blog.51cto.com/7002794/1241208

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.