Automatically install a script that configures the HTTPD virtual host

Source: Internet
Author: User

Script practice, write a script to implement the configuration of the local Web server:

1, check whether the HTTPD package has been installed, if not, the use of Yum command installation; (need to configure the Yum source in advance)

2, cancel the center host, new 5 domain based virtual host, and provide a test home page, the homepage content for its corresponding FQDN:

Www.magedu.com,/vhosts/magedu

Bbs.magedu.com,/vhosts/bbs

Wp.magedu.com,/vhosts/wordpress

Pw.magedu.com,/VHOSTS/PW

Pma.magedu.com,/vhosts/phpmyadmin

3, check the modified configuration file syntax, if there is no problem, then start the httpd service, and request that after the service will start automatically;

#!/bin/bash

#Author Honway

#ScriptName Autosetwebserver

Setyum () {

echo "=============================================="

echo "Start backup files."

echo "Backup your. repo file to. repo.bak!"

echo "=============================================="

yum_conf_dir=/etc/yum.repos.d/

For Y in $YUM _conf_dir/*.repo; Todo

MV $Y $Y. Bak &>/dev/null

Done

echo "=============================================="

echo "Backup successfully."

echo "=============================================="

echo "Create a yum config file."

Cat >> $YUM _conf_dir/yumconf.repo <<eof

[Server]

Name=server

Baseurl=ftp://172.16.0.1/pub/server

Gpgcheck=0

Enabled=1

[VT]

Name=vt

Baseurl=ftp://172.16.0.1/pub/vt

Gpgcheck=0

Enabled=1

[Cluster]

Name=cluster

Baseurl=ftp://172.16.0.1/pub/cluster

Gpgeheck=0

[Clusterstorage]

Name=clusterstorage

Baseurl=ftp://172.16.0.1/pub/clusterstorage

Gpgcheck=0

Enabled=1

[Errata]

Name=errata

Baseurl=ftp://172.16.0.1/pub/errata

Gpgeheck=0

Enabled=0

Eof

echo "ok!"

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

echo "=============================================="

}

Createtestpage () {

echo "$u" > $URL _dir/index.html

}

Setyum

if! ' Rpm-qa | grep httpd &>/dev/null '; Then

echo "===============================>"

echo "Start install Httpd.please wait ..."

Yum-y Install httpd &>null

Else

echo "Install is not sucess,something error."

Fi

Setvirtualconfig () {

Sed-i ' s@\ (^documentroot[[:space:]]\{1,\} "/var/www/html" \) @#\1@g '/etc/httpd/conf/httpd.conf

Sed-i ' s@^#\ (namevirtualhost[[:space:]]\{1,\}[^[:space:]]\{1,\}:80$\) @\1@g '/etc/httpd/conf/httpd.conf

}

Setvirtualconfig

Mkdir-p/VHOSTS/{MAGEDU,BBS,WP,PW,PMA} &>/dev/null

Fqdn=magedu.com

F=/etc/httpd/conf/httpd.conf

For u in {www. $FQDN, bbs. $FQDN, WP. $FQDN, PW $FQDN, PMA. $FQDN}; Todo

Case "$u" in

"Www.magedu.com")

url_dir=/vhosts/magedu

Cat >> $f <<eof

<virtualhost *:80>

ServerName $u

DocumentRoot $URL _dir

</VirtualHost>

Eof

Createtestpage;;

"Bbs.magedu.com")

Url_dir=/vhosts/bbs

Cat >> $f <<eof

<virtualhost *:80>

ServerName $u

DocumentRoot $URL _dir

</VirtualHost>

Eof

Createtestpage;;

"Wp.magedu.com")

url_dir=/vhosts/wp

Cat >> $f <<eof

<virtualhost *:80>

ServerName $u

DocumentRoot $URL _dir

</VirtualHost>

Eof

Createtestpage;;

"Pw.magedu.com")

Url_dir=/vhosts/pw

Cat >> $f <<eof

<virtualhost *:80>

ServerName $u

DocumentRoot $URL _dir

</VirtualHost>

Eof

Createtestpage;;

"Pma.magedu.com")

Url_dir=/vhosts/pma

Cat >> $f <<eof

<virtualhost *:80>

ServerName $u

DocumentRoot $URL _dir

</VirtualHost>

Eof

Createtestpage;;

*)

echo "Error ...";

Esac

Done

If ' service httpd configtest '; Then

Chkconfig--level 345 httpd on

Service httpd Start

Fi

This article comes from "Acridine a Pooh" blog, please be sure to keep this source http://gm100861.blog.51cto.com/1930562/803162

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.