Skip to content

Instantly share code, notes, and snippets.

@CaporalDead
Created September 8, 2013 02:33
Show Gist options
  • Save CaporalDead/6481396 to your computer and use it in GitHub Desktop.
Save CaporalDead/6481396 to your computer and use it in GitHub Desktop.
Création d'un nouveau domaine (site hébergé) basé sur son nom de domaine
#!/bin/sh
# /usr/local/bin/create-domain
if [ -z "$1" ]; then
echo "First parameter must be a domain name"
exit 1
fi
DOMAIN_NAME=$1
APACHE_CONF_DIR=/etc/apache2/sites-available
DOMAINS_DIR=/data/www
APACHE_CONF_FILE=$APACHE_CONF_DIR/$DOMAIN_NAME
DOMAIN_DIR=$DOMAINS_DIR/$DOMAIN_NAME
if [ -d "$DOMAIN_DIR" ]; then
echo "A directory for your domain already exists"
exit 2
fi
if [ -e "$APACHE_CONF_FILE" ]; then
echo "An Apache file for your domain already exists"
exit 3
fi
cat <<EOF > $APACHE_CONF_FILE
## $DOMAIN_NAME
<VirtualHost *:1443>
ServerAdmin webmaster@$DOMAIN_NAME
ServerName www.$DOMAIN_NAME
ServerAlias $DOMAIN_NAME
DocumentRoot $DOMAIN_DIR/www/
<Directory $DOMAIN_DIR/www/>
DirectoryIndex index.html index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog $DOMAIN_DIR/logs/error.log
LogLevel warn
CustomLog $DOMAIN_DIR/logs/access.log combined
SSLEngine on
SSLCertificateFile /data/www/devitek.fr/ssl/server.pem
SSLCertificateKeyFile /data/www/devitek.fr/ssl/server.key
SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
# MSIE 6
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
EOF
mkdir -p $DOMAIN_DIR/logs
mkdir $DOMAIN_DIR/ssl
mkdir $DOMAIN_DIR/www
cat <<EOF > $DOMAIN_DIR/www/index.html
<h1>$DOMAIN_NAME</h1>
EOF
chmod 644 $APACHE_CONF_FILE
chmod 755 -R $DOMAIN_DIR
chown -R www-data:www-data $DOMAIN_DIR
a2ensite $DOMAIN_NAME
service apache2 reload
echo ""
echo "Your new domain is ready to use"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment