Skip to content

Instantly share code, notes, and snippets.

@leninhasda
Last active August 29, 2015 14:27
Show Gist options
  • Save leninhasda/0258c43877f9b8101ebd to your computer and use it in GitHub Desktop.
Save leninhasda/0258c43877f9b8101ebd to your computer and use it in GitHub Desktop.
a simple .sh file that i use to create new virtual host and directory structure in nginx for web application.
server {
listen 80;
listen [::]:80;
root /home/lenin/dev/devfolderroot/web;
index index.php index.html index.htm;
server_name domainname;
location / {
try_files $uri $uri/ /index.php?$args;
autoindex on;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
#!/bin/bash
isRoot(){
if [ "$(id -u)" != "0" ]; then
echo "WARNING: This script must be run as root. Script terminated!!"
exit 1
fi
}
# check if root user
isRoot
# get the app name
echo "Enter Project Name (all lower case) "
read appname
# replace space
appname="$(echo $appname | sed 's/ /-/g')"
appnameDev="$appname.dev"
# make app directory in dev
# and set permission
mkdir ~/dev/$appnameDev
mkdir ~/dev/$appnameDev/web
chmod 777 -R ~/dev/$appnameDev
# edit host
#hostedit="127.0.0.1 $appname.ice9\n127.0.0.1 www.$appname.ice9"
#echo -e $hostedit >> /etc/hosts
# create server config file
cp /etc/nginx/sites-available/base /etc/nginx/sites-available/$appname
sed -i "s/devfolderroot/$appnameDev/g" /etc/nginx/sites-available/$appname
sed -i "s/domainname/$appnameDev/g" /etc/nginx/sites-available/$appname
echo -e $confedit >> "/etc/nginx/sites-available/$appname"
# enable site
ln -s /etc/nginx/sites-available/$appname /etc/nginx/sites-enabled/$appname
# reload & restart server
service nginx reload
service nginx restart
echo "$appname created!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment