Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add custom folder name - tab instead of spaces for hosts file - defau…

…lt folder for vhost - adding port 80 for virtualhost
  • Loading branch information...
commit 8691578cd9d0877d6ee4ba10e52927a19c8b2859 1 parent 7674549
@LeonardDrs authored
Showing with 12 additions and 9 deletions.
  1. +12 −9 create-vhost
View
21 create-vhost
@@ -1,8 +1,9 @@
#!/bin/bash
-# Author: Marshall
+# Original Author: Marshall
# Description: Create Apache Virtual Hosts for MAMP
-# Homepage: https://github.com/marshallmick007/create-vhost
+# Homepage: https://github.com/marshallmick007/create-vhost
+# Custom Author: LeonardDrs
## Used in echo -e statements
E_PURPLE="\033[0;35m"
@@ -12,29 +13,30 @@ E_GREEN="\033[1;32m"
E_YELLOW="\033[1;33m"
# MAMP stuff
-APACHECONF="/Applications/MAMP/conf/apache/httpd-vhosts.conf"
+APACHECONF="/Applications/MAMP/conf/apache/extra/httpd-vhosts.conf"
LOGDIR="/Applications/MAMP/logs"
-VHOSTSDIR="${HOME}/Sites/vhosts"
+VHOSTSDIR="/Applications/MAMP/htdocs"
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
echo "Usage: create-vhost vhostname.tld"
else
SITE=$1
+ DOC=$2
if [ ! -d "${VHOSTSDIR}" ]; then
echo "VHOST directory ${VHOSTSDIR} does not exist, attempting to create it..."
mkdir "${VHOSTSDIR}"
fi
if [ -d "${VHOSTSDIR}" ]; then
- vdir="$VHOSTSDIR/${SITE}"
- echo -e "Creating vhost for domain ${E_GREEN}${SITE}${E_NC} at ${E_GREEN}${vdir}${E_NC}"
+ vdir="$VHOSTSDIR/${DOC}"
+ echo -e "Creating vhost for domain ${E_GREEN}${DOC}${E_NC} at ${E_GREEN}${vdir}${E_NC}"
if [ ! -d "${vdir}" ]; then
mkdir "${vdir}"
else
echo -e "> ${E_YELLOW}Directory ${vdir} already exists${E_NC}"
fi
- hfentry="127.0.0.1 ${SITE}"
+ hfentry="127.0.0.1"$'\t'"${SITE}"
hostfile=`cat /etc/hosts | grep -c ^"${hfentry}"`
if [ "0" = "${hostfile}" ]; then
sudo cp /etc/hosts /etc/hosts.bak
@@ -48,7 +50,8 @@ else
apacheentry="ServerName ${SITE}"
apacheexists=`cat ${APACHECONF} | grep -c "${apacheentry}"`
if [ "0" = "${apacheexists}" ]; then
- echo "<VirtualHost *>" >> $APACHECONF
+ echo -e "" >> $APACHECONF
+ echo "<VirtualHost *:80>" >> $APACHECONF
echo -e "\tDocumentRoot \"${vdir}\"" >> $APACHECONF
echo -e "\tServerName ${SITE}" >> $APACHECONF
echo -e "\tErrorLog '${LOGDIR}/${SITE}-error_log'" >> $APACHECONF
@@ -60,4 +63,4 @@ else
else
echo -e "${E_RED}Unable to create VHOST directory ${VHOSTSDIR}${E_NC}"
fi
-fi
+fi
Please sign in to comment.
Something went wrong with that request. Please try again.