Skip to content

Instantly share code, notes, and snippets.

@ljamel
Last active June 10, 2024 03:11
Show Gist options
  • Save ljamel/88499ce539cb26573d701de0cbe2a2ee to your computer and use it in GitHub Desktop.
Save ljamel/88499ce539cb26573d701de0cbe2a2ee to your computer and use it in GitHub Desktop.
#!/bin/bash
#creation de sous domaine
SUBDOMAIN="sub.example.org"
WEB_ROOT="/var/www/$SUBDOMAIN/"
APACHE_CONF="/etc/apache2/sites-available/$SUBDOMAIN.conf"
mkdir -p $WEB_ROOT
mkdir /var/www/$SUBDOMAIN
chown -R www-data:www-data /var/www/$SUBDOMAIN
chmod -R 755 /var/www/$SUBDOMAIN
tee $APACHE_CONF > /dev/null <<EOL
<VirtualHost *:80>
ServerName $SUBDOMAIN
DocumentRoot $WEB_ROOT
<Directory $WEB_ROOT>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog \${APACHE_LOG_DIR}/$SUBDOMAIN-error.log
CustomLog \${APACHE_LOG_DIR}/$SUBDOMAIN-access.log combined
</VirtualHost>
EOL
apt install apache2
# Activer le nouveau site
a2ensite $SUBDOMAIN.conf
/etc/init.d/apache2 restart
# Ajouter le sous-domaine au fichier hosts
sudo tee -a /etc/hosts > /dev/null <<EOL
127.0.0.1 $SUBDOMAIN
EOL
echo "Sous-domaine $SUBDOMAIN configur avec succ s."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment