Created
December 20, 2022 19:21
-
-
Save Padilo300/b2a894174290bef45fde380c18def024 to your computer and use it in GitHub Desktop.
apache virtual host add shell
This file contains hidden or 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 | |
domain=$1 | |
domain_conf_file_name="$domain.conf" | |
if test -z "$domain" | |
then | |
echo 'Вы не ввели название хоста' | |
exit 0 | |
fi | |
domain_exist=`ls /etc/apache2/sites-available/$domain_conf_file_name` | |
if [[ "$domain_exist" = "/etc/apache2/sites-available/$domain_conf_file_name" ]] | |
then | |
echo 'Домен уже существует. Выберите другое имя' | |
exit 0 | |
fi | |
echo "Создание виртуального хоста ($domain_conf_file_name) для домена $domain" | |
touch /etc/apache2/sites-available/$domain_conf_file_name; | |
echo "<VirtualHost *:80> | |
ServerName $domain | |
ServerAdmin webmaster@localhost | |
DocumentRoot /var/www/$domain/public | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
DumpIOInput On | |
DumpIOOutput On | |
LogLevel dumpio:trace7 | |
</VirtualHost>" >> /etc/apache2/sites-available/$domain_conf_file_name | |
domain_exist=`ls /etc/apache2/sites-available/$domain_conf_file_name` | |
if [[ "$domain_exist" = "/etc/apache2/sites-available/$domain_conf_file_name" ]] | |
echo 'ERROR! что-то пошло не так, не удалось найти файл домена после попытки создания!' | |
then | |
echo 'Домен успешно создан!' | |
echo "Выполняю a2ensite $domain_conf_file_name !" | |
a2ensite $domain_conf_file_name | |
echo "Выполняю перечитывание конфигов apachec (apachectl -k graceful)" | |
apachectl -k graceful | |
echo "Вывод Apache2 status" | |
systemctl status apache2 | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment