-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebserv.skript.sh
4948 lines (4565 loc) · 201 KB
/
webserv.skript.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Вывод цветных сообщений.
BLACK='\033[0;30m' # ${BLACK} # чёрный цвет знаков
RED='\033[0;31m' # ${RED} # красный цвет знаков
GREEN='\033[0;32m' # ${GREEN} # зелёный цвет знаков
YELLOW='\033[0;33m' # ${YELLOW} # желтый цвет знаков
BLUE='\033[0;34m' # ${BLUE} # синий цвет знаков
MAGENTA='\033[0;35m' # ${MAGENTA} # фиолетовый цвет знаков
CYAN='\033[0;36m' # ${CYAN} # цвет морской волны знаков
GRAY='\033[0;37m' # ${GRAY} # серый цвет знаков
NORMAL='\033[0m' # ${NORMAL} # все атрибуты по умолчанию
WHITE='\033[1;37m' # ${WHITE}
clear
p=`pwd`
function razryadnost_versia_OS {
#Данное условие проверяет разрядность системы 32/64 bit
if [ "$(uname -m)" == 'x86_64' ]
then
razrayd=64
else
razrayd=32
fi
veriaos=`cat /etc/redhat-release | awk -F 'release' '{print $2}' | awk -F '.' '{print $1}'`
if [[ "$veriaos" == ' 6' ]]; then
versiaOS=centos6
fi
if [[ "$veriaos" == ' 7' ]]; then
versiaOS=centos7
fi
}
function proverka_ustanovlennogo_PO {
razryadnost_versia_OS
rpm -qa | grep -E 'httpd|nginx|mysql|maria|php|proftp|samba|openvpn|telnet|wget|vim|docker|php-fpm|php54-php-fpm|php55-php-fpm|php56-php-fpm|php70-php-fpm|php71-php-fpm|php72-php-fpm|yum-utils|net-tools|ansible' > $p/ustanovlennoe_PO
apache=`cat $p/ustanovlennoe_PO | grep httpd | awk -F '-' '{print $1}' | head -1`
nginx=`cat $p/ustanovlennoe_PO | grep nginx | awk -F '-' '{print $1}' | head -1`
mysql=`cat $p/ustanovlennoe_PO | grep -E 'mysql|maria' | grep server | awk -F '-' '{print $1}' | head -1`
php=`cat $p/ustanovlennoe_PO | grep php | awk -F '-' '{print $1}' | head -1`
proftpd=`cat $p/ustanovlennoe_PO | grep proftp | awk -F '-' '{print $1}' | head -1`
samba=`cat $p/ustanovlennoe_PO | grep samba | head -1 | awk -F '-' '{print $1}'`
openvpn=`cat $p/ustanovlennoe_PO | grep openvpn | awk -F '-' '{print $1}' | head -1`
telnet=`cat $p/ustanovlennoe_PO | grep telnet | awk -F '-' '{print $1}' | head -1`
wget=`cat $p/ustanovlennoe_PO | grep wget | awk -F '-' '{print $1}' | head -1`
ansible=`cat $p/ustanovlennoe_PO | grep ansible | awk -F '-' '{print $1}' | head -1`
vim=`cat $p/ustanovlennoe_PO | grep vim |grep -v minimal| awk -F '-' '{print $1}' | head -1`
docker=`cat $p/ustanovlennoe_PO | grep docker | awk -F '-' '{print $1}' | head -1`
php_fpm=`cat $p/ustanovlennoe_PO | grep ^php-fpm | awk -F '-' '{print $1"-"$2}' | head -1`
yum_utils=`cat $p/ustanovlennoe_PO | grep ^yum-utils | awk -F '-' '{print $1"-"$2}' | head -1`
net_tools=`cat $p/ustanovlennoe_PO | grep net-tools | awk -F '-' '{print $1"-"$2}' | head -1`
php54_php_fpm=`cat $p/ustanovlennoe_PO | grep php54-php-fpm | awk -F '-' '{print $1"-"$2"-"$3}' | head -1`
php55_php_fpm=`cat $p/ustanovlennoe_PO | grep php55-php-fpm | awk -F '-' '{print $1"-"$2"-"$3}' | head -1`
php56_php_fpm=`cat $p/ustanovlennoe_PO | grep php56-php-fpm | awk -F '-' '{print $1"-"$2"-"$3}' | head -1`
php70_php_fpm=`cat $p/ustanovlennoe_PO | grep php70-php-fpm | awk -F '-' '{print $1"-"$2"-"$3}' | head -1`
php71_php_fpm=`cat $p/ustanovlennoe_PO | grep php71-php-fpm | awk -F '-' '{print $1"-"$2"-"$3}' | head -1`
php72_php_fpm=`cat $p/ustanovlennoe_PO | grep php72-php-fpm | awk -F '-' '{print $1"-"$2"-"$3}' | head -1`
rm -f $p/ustanovlennoe_PO
if [ "$apache" == 'httpd' ]
then
ap=y #апач установлен
else
ap=n
fi
if [ "$nginx" == 'nginx' ]
then
ng=y
else
ng=n
fi
if [[ "$nginx" == 'nginx' && "$ap" == 'y' ]];
then
port_nginx=80
port_apache=8080
fr_bk_end=y #frontend и backend установлены
else
fr_bk_end=n
port_apache=80
fi
if [ "$mysql" == 'mysqld' ] || [ "$mysql" == 'mysql' ] || [ "$mysql" == 'mariadb' ];
then
mys=y #mysql установлен
else
mys=n
fi
if [ "$php" == 'php' ]
then
ph=y #php установлен
else
ph=n
fi
if [ "$wget" != 'wget' ]
then
yum -y install wget
fi
if [ "$vim" != 'vim' ]
then
yum -y install vim
fi
if [ "$telnet" != 'telnet' ]
then
yum -y install telnet
fi
if [ "$yum_utils" != 'yum-utils' ]
then
yum -y install yum-utils
fi
if [ "$net_tools" != 'net-tools' ]
then
yum -y install net-tools
fi
}
function podkluchenie_repozitoria_epel_centos6 {
razryadnost_versia_OS
Epel=`yum repolist | grep epel | head -1 | awk -F '*' '{print $2}' | awk -F ':' '{print $1}' | sed s/' '//g`
if [ "$Epel" != 'epel' ]; then
yum -y install yum-utils yum-priorities
if [ "$razrayd" == '64' ]; then
echo -e "${YELLOW}Подключаем репозиторий Epel${NORMAL}"
rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
else
echo -e "${YELLOW}Подключаем репозиторий Epel${NORMAL}"
rpm --import http://elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
fi
fi
}
function podkluchenie_repozitoria_epel_centos7 {
razryadnost_versia_OS
Epel=`yum repolist | grep epel | head -1 | awk -F '*' '{print $2}' | awk -F ':' '{print $1}' | sed s/' '//g`
if [ "$Epel" != 'epel' ]; then
yum -y install yum-utils yum-priorities
yum -y install epel-release
fi
}
function podkluchenie_repozitoria_remi_centos6 {
razryadnost_versia_OS
rem=`yum repolist | grep remi | tail -1 | awk '{print $1}'`
if [ "$rem" != 'remi-safe' ]
then
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
fi
}
function podkluchenie_repozitoria_remi_centos7 {
razryadnost_versia_OS
rem=`yum repolist | grep remi | tail -1 | awk '{print $1}'`
if [ "$rem" != 'remi-safe' ]
then
rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
fi
}
function ustanovka_apache_centos6 {
razryadnost_versia_OS
proverka_ustanovlennogo_PO
if [ "$ap" == 'n' ]
then
echo -e "${GREEN}Apache не установлен, установить? y/n ?${NORMAL}"
read otv_apach
if [ "$otv_apach" == 'y' ]
then
podkluchenie_repozitoria_epel_centos6
echo ""
echo ""
echo -e "${RED}Мы ОТКЛЮЧИЛИ SELINUX чтобы можно было устаовить mod_fcgid${NORMAL}"
echo ""
echo ""
echo -e "${RED}После отключения SELINUX нужно перезагрузить сервер, чтобы изменения вступили в силу ${NORMAL}"
echo ""
echo ""
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# В файле /etc/selinux/config была заменена строка SELINUX=enforcing на SELINUX=disabled
yum -y install httpd mod_fcgid
sed -i 's|#ServerName www.example.com:80|ServerName www.example.com:80|' /etc/httpd/conf/httpd.conf
sed -i 's|#NameVirtualHost \*:80|NameVirtualHost \*:80|' /etc/httpd/conf/httpd.conf
sed -i 's|ServerTokens OS|ServerTokens ProductOnly|' /etc/httpd/conf/httpd.conf
sed -i 's|ServerSignature On|ServerSignature Off|' /etc/httpd/conf/httpd.conf
# ставим mod_rpaf, чтобы в логе Apache отображались корректные IP, а не 127.0.0.1
# yum -y install httpd-devel gcc
# echo "178.236.176.177 stderr.net" >> /etc/hosts
# wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
# tar zxvf mod_rpaf-0.6.tar.gz
# rm -rf mod_rpaf-0.6.tar.gz
# sed -i '/178.236.176.177 stderr.net/ d' /etc/hosts
# cd mod_rpaf-0.6
# apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
yum -y install httpd-devel gcc gcc-c++ unar
wget wget http://seak.ru/filez/mod_rpaf_2.0c_apache2.4.7.rar
# wget http://abcname.com.ua/torrent/mod_rpaf.tar.gz
# tar xzf mod_rpaf.tar.gz
unar mod_rpaf_2.0c_apache2.4.7.rar
# rm -rf mod_rpaf.tar.gz
rm -rf mod_rpaf_2.0c_apache2.4.7.rar
# cd mod_rpaf-0.6
cd mod_rpaf_2.0c
apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
echo "LoadModule rpaf_module modules/mod_rpaf-2.0.so
# mod_rpaf configuration
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
RPAFheader X-Forwarded-For" > /etc/httpd/conf.d/mod_rpaf.conf
chkconfig httpd on
service httpd start
else
exit 1;
fi
fi
}
function ustanovka_apache_centos7 {
razryadnost_versia_OS
proverka_ustanovlennogo_PO
if [ "$ap" == 'n' ]
then
echo -e "${GREEN}Apache не установлен, установить? y/n ?${NORMAL}"
read otv_apach
if [ "$otv_apach" == 'y' ]
then
podkluchenie_repozitoria_epel_centos7
echo ""
echo ""
echo -e "${RED}Мы ОТКЛЮЧИЛИ SELINUX чтобы можно было устаовить mod_fcgid${NORMAL}"
echo ""
echo ""
echo -e "${RED}После отключения SELINUX нужно перезагрузить сервер, чтобы изменения вступили в силу ${NORMAL}"
echo ""
echo ""
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# В файле /etc/selinux/config была заменена строка SELINUX=enforcing на SELINUX=disabled
yum -y install httpd mod_fcgid
sed -i 's|#ServerName www.example.com:80|ServerName www.example.com:80|' /etc/httpd/conf/httpd.conf
sed -i 's|#NameVirtualHost \*:80|NameVirtualHost \*:80|' /etc/httpd/conf/httpd.conf
sed -i 's|ServerTokens OS|ServerTokens ProductOnly|' /etc/httpd/conf/httpd.conf
sed -i 's|ServerSignature On|ServerSignature Off|' /etc/httpd/conf/httpd.conf
# ставим mod_rpaf, чтобы в логе Apache отображались корректные IP, а не 127.0.0.1
yum -y install httpd-devel gcc gcc-c++ unar
wget wget http://seak.ru/filez/mod_rpaf_2.0c_apache2.4.7.rar
unar mod_rpaf_2.0c_apache2.4.7.rar
cd mod_rpaf_2.0c
apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
# wget http://abcname.com.ua/torrent/mod_rpaf.tar.gz
# tar xzf mod_rpaf.tar.gz
# rm -rf mod_rpaf.tar.gz
sed -i 's|remote_ip|client_ip|g' $p/mod_rpaf_2.0c/mod_rpaf.c
sed -i 's|remote_ip|client_ip|g' $p/mod_rpaf_2.0c/mod_rpaf-2.0.c
sed -i 's|remote_addr|client_addr|g' $p/mod_rpaf_2.0c/mod_rpaf.c
sed -i 's|remote_addr|client_addr|g' $p/mod_rpaf_2.0c/mod_rpaf-2.0.c
cd $p/mod_rpaf_2.0c
apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
echo "LoadModule rpaf_module modules/mod_rpaf-2.0.so
# mod_rpaf configuration
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1
RPAFheader X-Forwarded-For" > /etc/httpd/conf.d/mod_rpaf.conf
systemctl enable httpd
systemctl start httpd
else
exit 1;
fi
fi
}
function ustanovka_nginx_centos6 {
razryadnost_versia_OS
proverka_ustanovlennogo_PO
if [[ "$ap" == 'y' && "$ng" == 'n' ]];
then
echo -e "${GREEN}Nginx не установлен, установить? y/n ?${NORMAL}"
read otv_nginx
if [ "$otv_nginx" == 'y' ]
then
ng_rep=`yum repolist | grep nginx | awk '{print $1}'`
if [ "$ng_rep" != 'nginx' ]
then
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
ng_rep=`yum repolist | grep nginx | awk '{print $1}'`
fi
if [ "$ng_rep" == 'nginx' ]
then
yum -y install nginx
#Создаём резервную копию конфиг файлов apache и nginx
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bkp
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bkp
#Меняем порты
sed -i 's|^Listen 80$|Listen 8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^#ServerName www.example.com:80$|ServerName www.example.com:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^#NameVirtualHost \*:80$|NameVirtualHost \*:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^ServerName www.example.com:80$|ServerName www.example.com:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^NameVirtualHost \*:80$|NameVirtualHost \*:8080|' /etc/httpd/conf/httpd.conf
echo "user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '
'\$status \$body_bytes_sent \"\$http_referer\" '
'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
server_tokens off;
keepalive_timeout 65;
#gzip on;
proxy_redirect off;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default;
location ~ /.ht {
deny all;
}
location / {
proxy_pass http://127.0.0.1:8080;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}" > /etc/nginx/nginx.conf
chkconfig nginx on
service httpd restart
service nginx start
fi
#Закоменченные else exit 1; нужны для того, чтобы можно было работать как при связке apache nginx так и на голом apache
#else
#exit 1;
fi
fi
}
function ustanovka_nginx_centos7 {
razryadnost_versia_OS
proverka_ustanovlennogo_PO
if [[ "$ap" == 'y' && "$ng" == 'n' ]];
then
echo -e "${GREEN}Nginx не установлен, установить? y/n ?${NORMAL}"
read otv_nginx
if [ "$otv_nginx" == 'y' ]
then
podkluchenie_repozitoria_epel_centos7
yum -y install nginx
#Создаём резервную копию конфиг файлов apache и nginx
cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bkp
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bkp
#Меняем порты
sed -i 's|^Listen 80$|Listen 8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^#ServerName www.example.com:80$|ServerName www.example.com:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^#NameVirtualHost \*:80$|NameVirtualHost \*:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^ServerName www.example.com:80$|ServerName www.example.com:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^NameVirtualHost \*:80$|NameVirtualHost \*:8080|' /etc/httpd/conf/httpd.conf
echo "user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '
'\$status \$body_bytes_sent \"\$http_referer\" '
'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
server_tokens off;
keepalive_timeout 65;
#gzip on;
proxy_redirect off;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default;
location ~ /.ht {
deny all;
}
location / {
proxy_pass http://127.0.0.1:8080;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}" > /etc/nginx/nginx.conf
systemctl enable nginx
systemctl restart httpd
systemctl restart nginx
fi
#Закоменченные else exit 1; нужны для того, чтобы можно было работать как при связке apache nginx так и на голом apache
#else
#exit 1;
fi
}
function ustanovka_mysql_centos6 {
razryadnost_versia_OS
if [ "$mys" == 'n' ]
then
echo -e "${GREEN}Mysql не установлен, установить? y/n ?${NORMAL}"
read otv_mysql
if [ "$otv_mysql" == 'y' ]
then
clear
echo -e "${YELLOW}Какую версию MYSQL Вы хотите установить:${NORMAL}"
echo -e "${WHITE}\"1\"${NORMAL} = ${RED}5.1${NORMAL}"
echo -e "${WHITE}\"2\"${NORMAL} = ${RED}5.5${NORMAL}"
read otv_ver_mysql
case $otv_ver_mysql in
1)
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo 2>/dev/null
yum -y install mysql mysql-server
chkconfig mysqld on
service mysqld start
;;
2)
podkluchenie_repozitoria_remi_centos6
sed -i '10c\enabled=1\' /etc/yum.repos.d/remi.repo
yum -y install mysql mysql-server
chkconfig mysqld on
service mysqld start
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo
;;
esac
echo ""
echo -e "${YELLOW}Произведём первоначальную настройку${NORMAL}"
echo ""
service mysqld restart
/usr/bin/mysql_secure_installation
else
#exit 1;
echo ""
fi
fi
}
function ustanovka_mysql_centos7 {
razryadnost_versia_OS
if [ "$mys" == 'n' ]
then
echo -e "${GREEN}Mysql не установлен, установить? y/n ?${NORMAL}"
read otv_mysql
if [ "$otv_mysql" == 'y' ]
then
clear
echo -e "${YELLOW}Какую версию MYSQL Вы хотите установить:${NORMAL}"
echo -e "${WHITE}\"1\"${NORMAL} = ${RED}mariadb-5.5${NORMAL}"
echo -e "${WHITE}\"2\"${NORMAL} = ${RED}mysql-5.7${NORMAL}"
read otv_ver_mysql
case $otv_ver_mysql in
1)
yum -y install mysql mariadb-server
systemctl enable mariadb
systemctl start mariadb
echo -e "${GREEN}При запросе пароля, нажмите ENTER:${NORMAL}"
;;
2)
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
yum install -y mysql mysql-server
systemctl enable mysqld
systemctl start mysqld
echo -e "${GREEN}Временный пароль указанный при создании:${NORMAL}"
sleep 2
grep 'temporary password is generated' /var/log/mysqld.log | awk '{print $11}'
;;
esac
echo ""
echo -e "${YELLOW}Произведём первоначальную настройку${NORMAL}"
echo ""
/usr/bin/mysql_secure_installation
else
# exit 1;
echo ""
fi
fi
}
function ustanovka_PHP_centos6 {
razryadnost_versia_OS
#proverka_ustanovlennogo_PO
if [ "$ph" == 'n' ]
then
echo -e "${GREEN}PHP не установлен, установить? y/n ?${NORMAL}"
read otv_php
if [ "$otv_php" == 'y' ]
then
echo ""
echo -e "${YELLOW}Какую версию PHP Вы хотите установить:${NORMAL}"
echo -e "${WHITE}\"1\"${NORMAL} = ${YELLOW}PHP.5.3${NORMAL}"
echo -e "${WHITE}\"2\"${NORMAL} = ${YELLOW}PHP.5.4${NORMAL}"
echo -e "${WHITE}\"3\"${NORMAL} = ${YELLOW}PHP.5.5${NORMAL}"
echo -e "${WHITE}\"4\"${NORMAL} = ${YELLOW}PHP.5.6${NORMAL}"
echo -e "${WHITE}\"5\"${NORMAL} = ${YELLOW}PHP.7.0${NORMAL}"
echo -e "${WHITE}\"6\"${NORMAL} = ${YELLOW}PHP.7.1${NORMAL}"
echo -e "${WHITE}\"7\"${NORMAL} = ${YELLOW}PHP.7.2${NORMAL}"
read otv_ver
case $otv_ver in
1)
podkluchenie_repozitoria_epel_centos6
rem=`yum repolist | grep remi | tail -1 | awk '{print $1}'`
# Данное условие нужно, в случае если репозиторий remi уже был подключен и какую-то версию PHP уже ставили
if [ "$rem" == 'remi-safe' ]
then
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
fi
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
2)
podkluchenie_repozitoria_epel_centos6
podkluchenie_repozitoria_remi_centos6
#установка php5.4
sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '10c\enabled=1\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php54
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
3)
podkluchenie_repozitoria_epel_centos6
podkluchenie_repozitoria_remi_centos6
#установка php5.5
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=1\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php55
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
4)
podkluchenie_repozitoria_epel_centos6
podkluchenie_repozitoria_remi_centos6
#установка php5.6
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=1\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php56
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
5)
podkluchenie_repozitoria_epel_centos6
podkluchenie_repozitoria_remi_centos6
#установка php7.0
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php70
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
6)
podkluchenie_repozitoria_epel_centos6
podkluchenie_repozitoria_remi_centos6
#установка php7.1
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php71
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
7)
podkluchenie_repozitoria_epel_centos6
podkluchenie_repozitoria_remi_centos6
#установка php7.2
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php72
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
esac
echo ""
echo -e "${YELLOW}В каком режиме PHP должен работать?${NORMAL}"
echo -e "${WHITE}\"1\"${NORMAL} = ${YELLOW}Как модуль apache${NORMAL}"
echo -e "${WHITE}\"2\"${NORMAL} = ${YELLOW}Как Fastcgi${NORMAL} ${RED}(Рекомендуется)${NORMAL}"
read otv_rez_rab
if [ "$otv_rez_rab" == '2' ]
then
yum -y install php-cgi mod_fcgid
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.bkp
echo " # This is the Apache server configuration file for providing FastCGI support
# through mod_fcgid
#
# Documentation is available at
# http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
LoadModule fcgid_module modules/mod_fcgid.so
# Use FastCGI to process .fcg .fcgi & .fpl scripts
AddHandler fcgid-script fcg fcgi fpl
# Sane place to put sockets and shared memory file
FcgidIPCDir /var/run/mod_fcgid
FcgidProcessTableFile /var/run/mod_fcgid/fcgid_shm
DirectoryIndex index.php
PHP_Fix_Pathinfo_Enable 1
FcgidMaxRequestLen 50000000" > /etc/httpd/conf.d/fcgid.conf
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g' /etc/php.ini
echo ""
echo "Wrapper будет добавлен при создании домена, так как владелец должен соответсвовать пользователю под которым будет работать сайт"
echo ""
else
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.bkp #переименовываем так как в виртуалхосте всё равно будем подключать php5_module
echo ""
echo "OK PHP будет работать как модуль apache"
echo ""
fi
else
exit 1;
fi
fi
}
function ustanovka_PHP_centos7 {
razryadnost_versia_OS
#proverka_ustanovlennogo_PO
if [ "$ph" == 'n' ]
then
echo -e "${GREEN}PHP не установлен, установить? y/n ?${NORMAL}"
read otv_php
if [ "$otv_php" == 'y' ]
then
echo ""
echo -e "${YELLOW}Какую версию PHP Вы хотите установить:${NORMAL}"
echo -e "${WHITE}\"1\"${NORMAL} = ${YELLOW}PHP.5.4${NORMAL}"
echo -e "${WHITE}\"2\"${NORMAL} = ${YELLOW}PHP.5.5${NORMAL}"
echo -e "${WHITE}\"3\"${NORMAL} = ${YELLOW}PHP.5.6${NORMAL}"
echo -e "${WHITE}\"4\"${NORMAL} = ${YELLOW}PHP.7.0${NORMAL}"
echo -e "${WHITE}\"5\"${NORMAL} = ${YELLOW}PHP.7.1${NORMAL}"
echo -e "${WHITE}\"6\"${NORMAL} = ${YELLOW}PHP.7.2${NORMAL}"
read otv_ver
case $otv_ver in
1)
podkluchenie_repozitoria_epel_centos7
podkluchenie_repozitoria_remi_centos7
#установка php5.4
sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '10c\enabled=1\' /etc/yum.repos.d/
remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/re
mi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php54
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
2)
podkluchenie_repozitoria_epel_centos7
podkluchenie_repozitoria_remi_centos7
#установка php5.5
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=1\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php55
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
3)
podkluchenie_repozitoria_epel_centos7
podkluchenie_repozitoria_remi_centos7
#установка php5.6
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=1\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php56
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
4)
podkluchenie_repozitoria_epel_centos7
podkluchenie_repozitoria_remi_centos7
#установка php7.0
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php70
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
5)
podkluchenie_repozitoria_epel_centos7
podkluchenie_repozitoria_remi_centos7
#установка php7.1
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php71
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
6)
podkluchenie_repozitoria_epel_centos7
podkluchenie_repozitoria_remi_centos7
#установка php7.2
sed -i '10c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '20c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '30c\enabled=0\' /etc/yum.repos.d/remi.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php54.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php70.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php71.repo && sed -i '9c\enabled=0\' /etc/yum.repos.d/remi-php72.repo
yum-config-manager --enable remi-php72
yum -y install php php-common php-cli php-devel php-gd php-mbstring php-mcrypt php-mysql php-odbc php-pdo php-soap php-tidy php-xml php-xmlrpc mod_fcgid
;;
esac
echo ""
echo -e "${YELLOW}В каком режиме PHP должен работать?${NORMAL}"
echo -e "${WHITE}\"1\"${NORMAL} = ${YELLOW}Как модуль apache${NORMAL}"
echo -e "${WHITE}\"2\"${NORMAL} = ${YELLOW}Как Fastcgi${NORMAL} ${RED}(Рекомендуется)${NORMAL}"
read otv_rez_rab
if [ "$otv_rez_rab" == '2' ]
then
yum -y install php-cgi mod_fcgid
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.bkp
echo " # This is the Apache server configuration file for providing FastCGI support
# through mod_fcgid
#
# Documentation is available at
# http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
LoadModule fcgid_module modules/mod_fcgid.so
# Use FastCGI to process .fcg .fcgi & .fpl scripts
AddHandler fcgid-script fcg fcgi fpl
# Sane place to put sockets and shared memory file
FcgidIPCDir /var/run/mod_fcgid
FcgidProcessTableFile /var/run/mod_fcgid/fcgid_shm
DirectoryIndex index.php
PHP_Fix_Pathinfo_Enable 1
FcgidMaxRequestLen 50000000" > /etc/httpd/conf.d/fcgid.conf
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g' /etc/php.ini
echo ""
echo "Wrapper будет добавлен при создании домена, так как владелец должен соответсвовать пользователю под которым будет работать сайт"
echo ""
else
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.bkp #переименовываем так как в виртуалхосте всё равно будем подключать php5_module
echo ""
echo "OK PHP будет работать как модуль apache"
echo ""
fi
else
exit 1;
fi
fi
}
function virthost_apache_dobavlenie {
proverka_ustanovlennogo_PO
clear
if [ "$ng" == 'n' ] # если ранее nginx был установлен и порт был изменён то условие ниже вернёт апач на 80 порт
then
sed -i 's|^Listen 8080$|Listen 80|' /etc/httpd/conf/httpd.conf
sed -i 's|^ServerName www.example.com:8080$|ServerName www.example.com:80|' /etc/httpd/conf/httpd.conf
sed -i 's|^NameVirtualHost \*:8080$|NameVirtualHost \*:80|' /etc/httpd/conf/httpd.conf
sed -i 's|^#ServerName www.example.com:8080$|ServerName www.example.com:80|' /etc/httpd/conf/httpd.conf
sed -i 's|^#NameVirtualHost \*:8080$|NameVirtualHost \*:80|' /etc/httpd/conf/httpd.conf
fi
if [ "$ng" == 'y' ]
then
sed -i 's|^Listen 80$|Listen 8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^ServerName www.example.com:80$|ServerName www.example.com:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^NameVirtualHost \*:80$|NameVirtualHost \*:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^#ServerName www.example.com:80$|ServerName www.example.com:8080|' /etc/httpd/conf/httpd.conf
sed -i 's|^#NameVirtualHost \*:80$|NameVirtualHost \*:8080|' /etc/httpd/conf/httpd.conf
fi
echo -e "${CYAN}Введите домен${NORMAL}"
read domen
echo ""
echo -e "${CYAN}Введите пользователя под которым будет работать сайт${NORMAL}"
read user
homedir="/var/www/$user"
proverka_usera=`awk -F ":" '{print $1}' /etc/passwd | grep "^$user$"`
if [ "$proverka_usera" != "$user" ]
then
echo ""
echo -e "${RED}Извините, но такого пользователя нет, добавьте его${NORMAL}"
echo ""
echo -e "Добавить ${RED} $user ${NORMAL} y/n ??"
read otv
if [[ "$otv" == 'y' ]];
then
adduser $user
else
echo "ОК добавь сам и перезапусти скрипт $0"
exit 1;
fi
fi
echo ""
echo -e "${CYAN}Выберите, PHP для сайта "$domen" будет работать как модуль APACHE или как FASTCGI?${NORMAL}"
echo -e "${WHITE}\"1\"${NORMAL} = ${YELLOW}модуль Apache ${NORMAL}"
echo -e "${WHITE}\"2\"${NORMAL} = ${YELLOW}Fastcgi ${NORMAL}"
read otv_rezima_raboti
case $otv_rezima_raboti in
1)
php7=`php -v | head -1 | awk '{print $2}' | awk -F '.' '{print $1}'`
if [[ "$php7" != '7' ]];
then
echo "<VirtualHost *:$port_apache>
ServerAdmin webmaster@$domen
DocumentRoot $homedir/site/$domen
ServerName $domen
ServerAlias www.$domen
ErrorLog $homedir/logs/$domen.error.log
CustomLog $homedir/logs/$domen.access.log common
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule !prefork.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
DirectoryIndex index.php
</VirtualHost>" > /etc/httpd/conf.d/$domen.conf
else
echo "<VirtualHost *:$port_apache>
ServerAdmin webmaster@$domen
DocumentRoot $homedir/site/$domen
ServerName $domen
ServerAlias www.$domen
ErrorLog $homedir/logs/$domen.error.log
CustomLog $homedir/logs/$domen.access.log common
<IfModule prefork.c>
LoadModule php7_module modules/libphp7.so
</IfModule>
<IfModule !prefork.c>
LoadModule php7_module modules/libphp7-zts.so
</IfModule>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
AddType text/html .php
DirectoryIndex index.php
</VirtualHost>" > /etc/httpd/conf.d/$domen.conf
fi
# ниже перечисленные условия, проверяют созданы ли директории/файлы и если не созданы, то создают
if ! [ -d $homedir/site/$domen/ ]; then
mkdir -p $homedir/site/$domen
fi
if ! [ -d $homedir/logs/ ]; then
mkdir $homedir/logs
fi
if ! [ -f $homedir/logs/$domen.error.log ]; then
touch $homedir/logs/$domen.error.log
fi
if ! [ -f $homedir/logs/$domen.access.log ]; then
touch $homedir/logs/$domen.access.log
fi
chown -R $user:$user $homedir
echo ""
echo -e "${WHITE}Проверям синтаксис apache, если ошибок нет apache будет перезагружен${NORMAL}"
echo ""
httpd -t 2> $p/peremen.syntax
apachSyntax=`cat $p/peremen.syntax| grep 'Syntax OK'`
if [ "$apachSyntax" == 'Syntax OK' ]
then
if [[ "$versiaOS" == "centos6" ]];
then
service httpd restart
fi
if [[ "$versiaOS" == "centos7" ]];
then
systemctl restart httpd
fi
fi
rm $p/peremen.syntax
;;
2)
# если при установке PHP было указано, что PHP должен работать как модуль apache, а при добавлении домена решили установить его как Fastcgi, то условие ниже всё поправит.
if [ -f /etc/httpd/conf.d/php.conf ] || [ -f /etc/httpd/conf.d/php.conf.bkp ] ; then
if [ "$(rpm -qa | grep php-cli | awk -F "-" '{print $1"-"$2}')" != 'php-cli' ]; then
yum -y install php-cgi mod_fcgid
fi
if [ -f /etc/httpd/conf.d/php.conf ] ; then
mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.bkp
fi
echo " # This is the Apache server configuration file for providing FastCGI support
# through mod_fcgid
#
# Documentation is available at
# http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
LoadModule fcgid_module modules/mod_fcgid.so
# Use FastCGI to process .fcg .fcgi & .fpl scripts
AddHandler fcgid-script fcg fcgi fpl
# Sane place to put sockets and shared memory file
FcgidIPCDir /var/run/mod_fcgid
FcgidProcessTableFile /var/run/mod_fcgid/fcgid_shm
DirectoryIndex index.php
PHP_Fix_Pathinfo_Enable 1
FcgidMaxRequestLen 50000000" > /etc/httpd/conf.d/fcgid.conf
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g' /etc/php.ini
fi
# условие завершено
echo "<VirtualHost *:$port_apache>
ServerAdmin webmaster@$domen
DocumentRoot $homedir/site/$domen
ServerName $domen
ServerAlias www.$domen
ErrorLog $homedir/logs/$domen.error.log
CustomLog $homedir/logs/$domen.access.log common
<IfModule mod_fcgid.c>
SuexecUserGroup $user $user
<Directory $homedir/site/$domen>
Options +ExecCGI
AllowOverride All
AddHandler fcgid-script .php
FCGIWrapper $homedir/php-cgi/php.cgi .php
Order allow,deny
Allow from all
</Directory>
</IfModule>
</VirtualHost>" > /etc/httpd/conf.d/$domen.conf
# ниже перечисленные условия, проверяют созданы лы директории/файлы и если не созданы, то создают
if ! [ -d $homedir/site/$domen/ ]; then
mkdir -p $homedir/site/$domen
fi
if ! [ -d $homedir/logs/ ]; then
mkdir $homedir/logs
fi
if ! [ -d $homedir/php-cgi/ ]; then
mkdir $homedir/php-cgi/
fi
if ! [ -f $homedir/logs/$domen.error.log ]; then
touch $homedir/logs/$domen.error.log
fi
if ! [ -f $homedir/logs/$domen.access.log ]; then
touch $homedir/logs/$domen.access.log
fi
if ! [ -f $homedir/php-cgi/php.cgi ]; then
touch $homedir/php-cgi/php.cgi
echo "#!/bin/sh
PHPRC=$homedir/php-cgi/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=500
exec /usr/bin/php-cgi" > $homedir/php-cgi/php.cgi
#В данном месте мы копируем php.ini, для того чтобы у каждого пользователя был свой (путь до php.ini указывается через параметр PHPRC, в FCGIWrapper - php.cgi)
cp /etc/php.ini $homedir/php-cgi/
chmod +x $homedir/php-cgi/php.cgi
fi
chown -R $user:$user $homedir
echo ""
echo -e "${WHITE}Проверям синтаксис apache, если ошибок нет apache будет перезапущен${NORMAL}"
echo ""