Created
February 24, 2012 09:32
-
-
Save fukata/1899732 to your computer and use it in GitHub Desktop.
Add virtualhost setting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
################################################################### | |
# | |
# 当スクリプトでは、以下のことを行う。 | |
# | |
# 1./etc/apache2/site-available, /etc/apache2/site-enabledへの | |
# VirtualHostの設定を記述したファイルを設置 | |
# 2./var/log/apache2に指定したドメインのディレクトリを作成 | |
# 3./etc/hostsに指定したドメインを追加 | |
# | |
# | |
# ・コマンド例 | |
# sudo sh ./addhost.sh Domain DocumentRoot | |
# | |
# ・オプション | |
# Domain: | |
# hostsに追加するドメイン名。 | |
# ブラウザで確認する際に使用するドメインでもある。 | |
# | |
# DocumentRoot: | |
# ドキュメントルート | |
# | |
# | |
################################################################### | |
CURRENT_DIR=$(pwd)/$(dirname $0) | |
APACHE_HOME=/etc/apache2 | |
APACHE_SITE_AVA=${APACHE_HOME}/sites-available | |
APACHE_SITE_ENA=${APACHE_HOME}/sites-enabled | |
TEMP=${CURRENT_DIR}/addhost_template | |
DOMAIN=${1?"EMPTY Domain"} | |
ROOT=${2?"EMPTY DocumentRoot"} | |
FILE=${DOMAIN} | |
# add apache conf | |
sudo sed -e s@#ARG_DOMAIN#@${DOMAIN}@g ${TEMP} | sed -e s@#ARG_ROOT#@${ROOT}@g > ${APACHE_SITE_AVA}/${FILE} | |
sudo ln -sn ${APACHE_SITE_AVA}/${FILE} ${APACHE_SITE_ENA}/${FILE} | |
# add apache log dir | |
sudo mkdir /var/log/apache2/${DOMAIN} | |
# add hosts | |
TMP_FILE=/etc/${DOMAIN}.tmp | |
HOSTS=/etc/hosts | |
TMP_HOSTS=${HOSTS}.tmp | |
sudo echo "127.0.0.1 ${DOMAIN}" > ${TMP_FILE} | |
sudo cp ${HOSTS} ${TMP_HOSTS} | |
sudo cat ${TMP_FILE} ${TMP_HOSTS} > ${HOSTS} | |
# delete tmp | |
sudo rm -fr ${TMP_FILE} | |
sudo rm -fr ${TMP_HOSTS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NameVirtualHost #ARG_DOMAIN#:80 | |
<VirtualHost #ARG_DOMAIN#:80> | |
ServerAdmin webmaster@localhost | |
ServerName #ARG_DOMAIN#:80 | |
DocumentRoot #ARG_ROOT# | |
<Directory /> | |
Options FollowSymLinks | |
AllowOverride None | |
</Directory> | |
<Directory #ARG_ROOT#> | |
Options Indexes FollowSymLinks MultiViews | |
AllowOverride All | |
Order allow,deny | |
allow from all | |
</Directory> | |
ErrorLog /var/log/apache2/#ARG_DOMAIN#/error.log | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache2/#ARG_DOMAIN#/access.log combined | |
ServerSignature On | |
</VirtualHost> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment