-
Notifications
You must be signed in to change notification settings - Fork 0
/
laravel-virtual-site.sh
82 lines (64 loc) · 2.13 KB
/
laravel-virtual-site.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
domain=$1
www_folder="/var/www/"
root="$www_folder$domain"
block="/etc/nginx/sites-available/$domain"
uri="uri"
query_string="query_string"
ip="127.0.0.1"
host_line="$ip\t$domain"
etc_hosts=/etc/hosts
# Create the Document Root directory
# sudo mkdir -p $root
sudo mkdir -p $root
# Assign ownership to your www-data user
sudo chown -R www-data:www-data "$www_folder$domain"
# Create the Nginx server block file:
sudo tee $block > /dev/null <<EOF
server {
listen 80;
listen [::]:80;
root $root/public;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name $domain;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files \$$uri \$$uri/ /index.php?\$$query_string;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.0-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
EOF
#Adding hostname entry to hosts file /etc/hosts
if [ -n "$(grep $domain /etc/hosts)" ]
then
echo "$domain already exists : $(grep $domain $etc_hosts)"
else
echo "Adding $domain to your $etc_hosts";
sudo -- sh -c -e "echo '$host_line' >> /etc/hosts";
if [ -n "$(grep $domain /etc/hosts)" ]
then
echo "$domain was added succesfully";
else
echo "Failed to Add $domain, Try again!";
fi
fi
# Link to make it available
sudo ln -s $block /etc/nginx/sites-enabled/
# Test configuration and reload if successful
sudo nginx -t && sudo service nginx reload