Skip to content

Instantly share code, notes, and snippets.

@ale10257
Last active May 9, 2017 20:17
Show Gist options
  • Save ale10257/a5cd4cecad0dced965713974903f0ec3 to your computer and use it in GitHub Desktop.
Save ale10257/a5cd4cecad0dced965713974903f0ec3 to your computer and use it in GitHub Desktop.
Create virtual hosts on Apapche2
#!/bin/bash
if (($(id -u) > 0)); then
echo "Вы не рут!!!"
exit 1
fi
echo -e "Введите имя пользователя"
read USER_NAME
ROOT_DIR="/var/www/$USER_NAME/public_html"
FILE=site_list
while read DOMAIN; do
CONF=/etc/apache2/sites-available/$DOMAIN.conf
DOMAIN_PATH=$ROOT_DIR/$DOMAIN
if ! [[ -d $DOMAIN_PATH ]]; then
mkdir $DOMAIN_PATH
chown -R $USER_NAME:$USER_NAME $DOMAIN_PATH
fi
echo "Создание виртуального хоста для домена $DOMAIN"
echo "<VirtualHost *:80>
ServerName $DOMAIN
ServerAlias www.$DOMAIN
DocumentRoot $DOMAIN_PATH
<IfModule mpm_itk_module>
AssignUserId $USER_NAME $USER_NAME
</IfModule>
<Directory $DOMAIN_PATH>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog $ROOT_DIR/logs/error_log_$DOMAIN
</VirtualHost>" > $CONF
echo "Включение виртуального хоста $DOMAIN"
a2ensite $DOMAIN
done < $FILE
echo "Обновление конфигурации Apache"
service apache2 restart
echo "Виртуальный хост создан"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment