Skip to content

Instantly share code, notes, and snippets.

@ahmadsoe
Last active December 27, 2015 17:29
Show Gist options
  • Save ahmadsoe/7362580 to your computer and use it in GitHub Desktop.
Save ahmadsoe/7362580 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Enter the name of the domain you wish to create"
read a
echo "Create DocumentRoot directory..."
if [ ! -d /var/www/$a ]; then
mkdir -p /var/www/$a/public_html
mkdir -p /var/www/$a/logs
else
echo -e "This domain already exists..."
read -p " Press [ENTER] to exit..."
exit
fi
echo "Setting Ownership..."
chown -R apache:apache /var/www/$a/public_html
echo "Adding to hosts file..."
echo "<VirtualHost *:80>" >> /etc/httpd/conf/httpd.conf
echo "ServerAdmin webmaster@$a" >> /etc/httpd/conf/httpd.conf
echo "DocumentRoot /var/www/$a/public_html" >> /etc/httpd/conf/httpd.conf
echo "ServerName $a" >> /etc/httpd/conf/httpd.conf
echo "ErrorLog /var/www/$a/logs/error.log" >> /etc/httpd/conf/httpd.conf
echo "CustomLog /var/www/$a/logs/access.log common" >> /etc/httpd/conf/httpd.conf
echo "</VirtualHost>" >> /etc/httpd/conf/httpd.conf
echo "Reload Apache..."
apachectl -k stop
/etc/init.d/httpd start
echo ""
echo "=================================================================="
echo -e "Finish! Your domain directory is /var/www/$a/public_html/"
echo "=================================================================="
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment