Skip to content

Instantly share code, notes, and snippets.

@santigarcor
Last active October 12, 2017 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santigarcor/90d1da61237f06ca29293d8ebc68f959 to your computer and use it in GitHub Desktop.
Save santigarcor/90d1da61237f06ca29293d8ebc68f959 to your computer and use it in GitHub Desktop.
Add a new site
#!/bin/bash
if [[ $(whoami) == "root" ]]; then
echo "Please don't run this script as sudo user"
exit 1
fi
inputWithDefault() {
read -r userInput
userInput=${userInput:-$1}
echo "$userInput"
}
username=$(whoami)
echo "Please enter the project name: (Default: default)"
siteName=$(inputWithDefault default)
siteFolder="/home/$username/$siteName"
echo "Are you going to use envoyer for the Laravel deployment?: (y/n) (Default: n)"
usingEnvoyer=$(inputWithDefault n)
if [ "$usingEnvoyer" == "y" ]; then
sitePath="/home/$username/${siteName}/current/public"
else
echo "Is the site a Laravel project?: (y/n) (Default: n)"
isALaravelProject=$(inputWithDefault n)
if [ "$isALaravelProject" == "y" ]; then
sitePath="/home/$username/${siteName}/public"
else
sitePath="/home/$username/$siteName"
fi
fi
echo "Please enter the project domain name/ip: (Default: localhost)"
serverName=$(inputWithDefault localhost)
mkdir "$siteFolder"
echo "<?php phpinfo();" > "$siteFolder/index.php"
siteConf="
server {
listen 80;
listen [::]:80;
server_name $serverName;
root $sitePath;
index index.html index.htm index.php ;
charset utf-8 ;
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
location = /favicon.ico { access_log off ; log_not_found off ; }
location = /robots.txt { access_log off ; log_not_found off ; }
access_log off;
error_log /var/log/nginx/$siteName-error.log error;
error_page 404 /index.php;
location ~ \\.php$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\\.php)(/.+)\$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
location ~ /\\.ht {
deny all;
}
}
"
echo "$siteConf" | sudo tee -a "/etc/nginx/sites-available/$siteName"
if [ ! -f "/etc/nginx/sites-enabled/$siteName" ]; then
sudo ln -s "/etc/nginx/sites-available/$siteName" "/etc/nginx/sites-enabled/$siteName"
fi
sudo service nginx reload
clear
echo "The site was configured successfully"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment