Skip to content

Instantly share code, notes, and snippets.

@ssmulders
Last active June 22, 2018 10:42
Show Gist options
  • Save ssmulders/67ba06216da81630b1189fb2f404e37a to your computer and use it in GitHub Desktop.
Save ssmulders/67ba06216da81630b1189fb2f404e37a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Quickly add a local deployment / nginx vhost on macOS
# Optionally with a laravel install.
#
# Usage
# ./site_add.sh testdomain.local
DOMAIN=$1
SITES_AVAILABLE="/usr/local/etc/nginx/sites-available"
SITES_ENABLED="/usr/local/etc/nginx/sites-available"
VHOSTS_LOCATION="/Users/stan/Dropbox/_LocalServer"
PERMISSIONS="stan:staff"
echo "Adding $DOMAIN to Nginx"
# Make sure this one exists. Check: https://gist.github.com/ssmulders/67d752ab0e42a6c9952418649091bc76
cp $SITES_AVAILABLE/default $SITES_AVAILABLE/$DOMAIN
mkdir -p VHOSTS_LOCATION/$DOMAIN/public_html
mkdir -p VHOSTS_LOCATION/$DOMAIN/logs
touch VHOSTS_LOCATION/$DOMAIN/logs/access.log;
touch VHOSTS_LOCATION/$DOMAIN/logs/error.log;
ln -s $SITES_AVAILABLE/$DOMAIN $SITES_ENABLED
sed -i '' 's/DOMAIN/'$DOMAIN'/g' $SITES_AVAILABLE/$DOMAIN
sudo nginx -s reload
sudo echo "127.0.0.1 $DOMAIN" >> /etc/hosts
sudo awk '!a[$0]++' /etc/hosts > tmp && cp tmp /etc/hosts && rm tmp
read -p "Would you like to install Laravel as well? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
sudo rm -rf public_html
laravel new public_html
mv public_html VHOSTS_LOCATION/$DOMAIN/
chown -R $PERMISSIONS VHOSTS_LOCATION/$DOMAIN/
fi
echo "All done! Visit https://$DOMAIN to see your brand new site."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment