/
lemp14.bash
146 lines (124 loc) · 3.88 KB
/
lemp14.bash
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
TEXTDOMAIN=lemp
function install_packages()
{
apt-get update && apt-get install -y --allow-unauthenticated ${@}
echo 'Package installation completed'
}
## Usage
print_help(){
cat <<EOH
Usage: $0 [-h] [-n]
-h | This help menu
-n | not installing MySQL
EOH
exit 1
}
nginx=/usr/share/nginx/html
### php-fpm restart command
restartfpm='service php5-fpm restart'
### nginx restart command
restartnginx='service nginx restart'
### set default nginx server block
nginxdefault='/etc/nginx/sites-available/default'
###check for root
if [ "$(whoami)" != 'root' ]; then
echo $"You don't have the permission to run $0 as non-root user. Sudo maybe?"
exit 1;
fi
###Install all necessary things!
function mysql(){
apt install nginx curl mysql-server php-fpm php-mysql -y
}
function nomysql(){
apt install nginx curl php5-fpm php5-mysql -y
}
function ipaddr(){
###Get IP/domain server
echo -n "Enter your Server IP or domain and press [ENTER]: "
read IP
}
### change /etc/php/7.0/fpm/conf.d/10-opcache.ini
function phpfpm7(){
opcache='/etc/php5/fpm/conf.d/05-opcache.ini'
sh -c "echo 'opcache.enable=0' >> $opcache"
cgifix='/etc/php5/fpm/php.ini'
sh -c "sed -i -e 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' $cgifix"
### restart php-fpm
$restartfpm
}
### edit
function editnginx(){
if ! echo "server {
listen 80 default_server;
listen [::]:80 default_server;
root /usr/share/nginx/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name $IP;
location / {
try_files \$uri \$uri/ =404;
}
location ~ \.php\$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}" >| $nginxdefault
then
echo -e $"There is an ERROR create $nginxdefault file"
exit;
else
echo -e $"New $nginxdefault Created."
fi
### make sure nginx can start with new config
nginx -t
### restart nginx
$restartnginx
}
function secureinstall(){
echo -e "\n\nValidate password sometimes messed up your password make sure to choose which suit you well...."
secure_mysql='mysql_secure_installation'
$secure_mysql
}
function trywrite(){
if ! echo $IP > $nginx/index.html
then
echo $"ERROR: Unable to write in $nginx/. Please check permissions."
exit;
else
echo $"Added index.html into $nginx/"
fi
if ! echo "<?php phpinfo(); ?>" > $nginx/info.php
then
echo $"ERROR: Unable to write in $nginx/. Please check permissions."
exit;
else
echo $"Added info.php into $nginx/"
fi
echo "You can check your webserver here http://$IP/info.php"
}
if [ "$1" = '-h' ]; then
print_help
fi
if [ "$1" = '-n' ]; then
install_packages
ipaddr
nomysql
phpfpm7
editnginx
trywrite
else
install_packages
ipaddr
mysql
secureinstall
phpfpm7
editnginx
trywrite
fi