-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·319 lines (265 loc) · 9.15 KB
/
install.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
reset
install_basics() {
# INSTALLING REQUIRED PACKAGES
yum install nano epel-release wget -y;
yum install unzip net-tools iperf3 htop atop nload net-snmp net-snmp-utils -y;
# DISABLING SELINUX
setenforce 0;
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux;
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config;
# INSTALLING REMI RELEASE
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
# DISABLING NETWORK MANAGER
service NetworkManager stop;
chkconfig NetworkManager off;
# DISABLING FIREWALL
service firewalld stop;
chkconfig firewalld off;
echo "Basic preparation has been completed successfully."
}
install_mariadb() {
cat >/etc/yum.repos.d/MariaDB.repo <<EOL
# MariaDB 10.5 CentOS repository list - created 2021-05-13 17:27 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOL
yum install MariaDB-server MariaDB-client -y;
# RESTARTING SERVICES & ENABLING SERVICES FOR AUTOSTART ON BOOT
sleep 1;
service mariadb restart;
sleep 1;
chkconfig mariadb on;
echo "MariaDB has been installed successfully."
}
install_nginx() {
yum install nginx -y
# RESTARTING SERVICES & ENABLING SERVICES FOR AUTOSTART ON BOOT
service nginx restart;
chkconfig nginx on;
echo "nginx has been installed successfully."
}
install_php() {
# INSTALLING PHP PACKAGES
yum --enablerepo=remi-php74 install php php-cli -y;
yum --enablerepo=remi-php74 install php-fpm php-opcache php-pdo php-gd php-mbstring php-mcrypt php-pear php-mysqlnd php-bcmath php-json php-xml php-sqlite3 php-curl -y;
pear channel-update pear.php.net
pear install Net_IPv4;
# CHANGING USER & GROUP PERMISSIONS TO NGINX
find /etc/php-fpm.d/ -type f -exec sed -i 's/apache/nginx/g' {} +;
mkdir /var/www/html;
mkdir /var/lib/php/session;
mkdir /var/lib/php/wsdlcache;
chown nginx:nginx /var/lib/php/session;
chown nginx:nginx /var/lib/php/wsdlcache;
chown nginx:nginx /var/lib/php/opcache;
# RESTARTING SERVICES & ENABLING SERVICES FOR AUTOSTART ON BOOT
sleep 1;
service php-fpm restart;
sleep 1;
chkconfig php-fpm on;
echo "PHP-FPM has been installed successfully."
}
create_db() {
DBNAME="${1}"
DBUSER="${2}"
DBPASS="${3}"
#CREATING MYSQL USER WITH GRANT PRIVILEGES & DATABASE
mysql -e "CREATE USER '${DBUSER}'@'localhost' IDENTIFIED BY '${DBPASS}';"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO '${DBUSER}'@'localhost' with GRANT OPTION;"
mysql -e "CREATE DATABASE ${DBNAME}";
mysql -e "ALTER DATABASE ${DBNAME} DEFAULT CHARSET=utf8 COLLATE utf8_general_ci";
echo "Database has been created successfully."
}
install_phpmyadmin() {
wget "https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-english.tar.gz" -O "/var/www/html/phpMyAdmin-5.1.0-english.tar.gz";
tar -zxf "/var/www/html/phpMyAdmin-5.1.0-english.tar.gz" --directory /var/www/html;
mv "/var/www/html/phpMyAdmin-5.1.0-english" "/var/www/html/phpmyadmin";
mv "/var/www/html/phpmyadmin/config.sample.inc.php" "/var/www/html/phpmyadmin/config.inc.php";
RANDOMHASH=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
sed -i 's/\$cfg\[\x27blowfish_secret\x27\] = \x27\x27;/\$cfg\[\x27blowfish_secret\x27\] = \x27'"$RANDOMHASH"'\x27;/g' "/var/www/html/phpmyadmin/config.inc.php"
chown nginx:nginx /var/www/html/ -R -f;
rm -Rf "/var/www/html/phpMyAdmin-5.1.0-english.tar.gz";
}
configure_nginx() {
cat >/etc/nginx/default.d/php.conf <<EOL
root /var/www/html;
location / {
index index.php index.html index.htm;
try_files \$uri \$uri/ /index.php?\$query_string;
}
add_header 'X-Frame-Options' 'DENY';
add_header 'X-Frame-Options' 'SAMEORIGIN';
add_header 'Access-Control-Allow-Origin' '*';
add_header 'X-Content-Type-Options' 'nosniff';
add_header 'X-XSS-Protection' '1; mode=block';
server_tokens off;
location ~* \.php\$ {
root /var/www/html;
try_files \$uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html\$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
EOL
sed -i 's/root/#root/g' /etc/nginx/nginx.conf;
sed -i.bak '47d;48d' /etc/nginx/nginx.conf
service php-fpm restart;
service httpd stop;
chkconfig httpd off;
service nginx restart;
}
configure_nginx_laravel() {
cat >/etc/nginx/default.d/laravel.conf <<EOL
root /var/www/html/laravel/public;
location / {
index index.php index.html index.htm;
try_files \$uri \$uri/ /index.php?\$query_string;
}
add_header 'X-Frame-Options' 'DENY';
add_header 'X-Frame-Options' 'SAMEORIGIN';
add_header 'Access-Control-Allow-Origin' '*';
add_header 'X-Content-Type-Options' 'nosniff';
add_header 'X-XSS-Protection' '1; mode=block';
server_tokens off;
location /phpmyadmin {
root /var/www/html;
index index.php;
location ~ ^/phpmyadmin/(.+\.php)\$ {
try_files \$uri =404;
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))\$ {
root /var/www/html;
}
}
location ~ \.php\$ {
root /var/www/html/laravel/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/laravel/public\$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
EOL
sed -i 's/root/#root/g' /etc/nginx/nginx.conf;
sed -i.bak '47d;48d' /etc/nginx/nginx.conf;
service httpd stop;
chkconfig httpd off;
service nginx restart;
}
install_laravel() {
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer;
composer create-project laravel/laravel /var/www/html/laravel;
chown nginx:nginx /var/www/html/ -R -f;
sed -i 's/;cgi\.fix_pathinfo=1/cgi\.fix_pathinfo=0/g' /etc/php.ini;
service php-fpm restart;
}
echo "CentOS 7 | nginx + MariaDB + PHP-FPM Stack Kickstart Installer"
echo "----------------------------------------------------------------"
echo " 1) Install NMP Stack"
echo " 2) Install NMP Stack + phpMyAdmin 5.x"
echo " 3) Install NMP Stack + phpMyAdmin 5.x + Create a DB with grant privileged user"
echo " 4) Install NMP Stack + phpMyAdmin 5.x + Create a DB with grant privileged user + Laravel"
echo " 5) Quit"
read n
case $n in
1)
echo "You chose Install NMP Stack"
install_basics
install_nginx
install_php
install_mariadb
;;
2)
echo "You chose NMP Stack + phpMyAdmin 5.x"
install_basics
install_nginx
install_php
install_mariadb
install_phpmyadmin
;;
3)
echo "You chose Install NMP Stack + phpMyAdmin 5.x + Create a DB with grant privileged user"
read -p "Enter database name: " DBNAME
read -p "Enter database username: " DBUSER
read -p "Enter database password: " DBPASS
echo "Don't forget to copy the following information, Creation will start after 5 seconds ...";
echo "Database name:" $DBNAME;
echo "Database username:" $DBUSER;
echo "Database password:" $DBPASS;
sleep 5;
if [ -z "$DBNAME" ] || [ -z "$DBUSER" ] || [ -z "$DBPASS" ]
then
echo 'Input cannot be blank, Please try again.'
exit 0
fi
install_basics
install_nginx
install_php
install_mariadb
create_db $DBNAME $DBUSER $DBPASS;
install_phpmyadmin
configure_nginx
;;
4)
echo "You chose Install NMP Stack + phpMyAdmin 5.x + Create a DB with grant privileged user"
read -p "Enter database name: " DBNAME
read -p "Enter database username: " DBUSER
read -p "Enter database password: " DBPASS
echo "Don't forget to copy the following information, Creation will start after 5 seconds ...";
echo "Database name:" $DBNAME;
echo "Database username:" $DBUSER;
echo "Database password:" $DBPASS;
sleep 5;
if [ -z "$DBNAME" ] || [ -z "$DBUSER" ] || [ -z "$DBPASS" ]
then
echo 'Input cannot be blank, Please try again.'
exit 0
fi
install_basics
install_nginx
install_php
install_mariadb
create_db $DBNAME $DBUSER $DBPASS;
install_phpmyadmin
install_laravel
configure_nginx_laravel
;;
5)
echo "Bye Bye"
exit
;;
*)
echo "invalid option"
;;
esac