forked from teddysun/lamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlamp.sh
1090 lines (1046 loc) · 35.2 KB
/
lamp.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
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#===============================================================================================
# System Required: CentOS / RedHat / Fedora
# Description: Install LAMP(Linux + Apache + MySQL + PHP ) for CentOS / RedHat / Fedora
# Author: Teddysun <[email protected]>
# Intro: http://teddysun.com/lamp
#===============================================================================================
clear
echo "#############################################################"
echo "# LAMP Auto Install Script for CentOS / RedHat / Fedora"
echo "# Intro: http://teddysun.com/lamp"
echo "#"
echo "# Author: Teddysun <[email protected]>"
echo "#"
echo "#############################################################"
echo ""
# Install time state
StartDate=''
StartDateSecond=''
# Software Version
MySQLVersion='mysql-5.6.22'
MySQLVersion2='mysql-5.5.41'
MariaDBVersion='mariadb-5.5.41'
MariaDBVersion2='mariadb-10.0.15'
PHPVersion='php-5.4.36'
PHPVersion2='php-5.3.29'
PHPVersion3='php-5.5.20'
ApacheVersion='httpd-2.4.10'
aprVersion='apr-1.5.1'
aprutilVersion='apr-util-1.5.3'
libiconvVersion='libiconv-1.14'
libmcryptVersion='libmcrypt-2.5.8'
mhashVersion='mhash-0.9.9.9'
mcryptVersion='mcrypt-2.6.8'
re2cVersion='re2c-0.13.6'
pcreVersion='pcre-8.36'
libeditVersion='libedit-20140620-3.1'
imapVersion='imap-2007f'
phpMyAdminVersion='phpMyAdmin-4.3.7-all-languages'
# Current folder
cur_dir=`pwd`
# CPU Number
Cpunum=`cat /proc/cpuinfo | grep 'processor' | wc -l`;
# Install LAMP Script
function install_lamp(){
rootness
disable_selinux
pre_installation_settings
download_all_files
untar_all_files
install_pcre
install_apache
install_database
install_libiconv
install_libmcrypt
install_mhash
install_mcrypt
install_re2c
install_libedit
install_imap
install_php
install_phpmyadmin
install_cleanup
}
# Get public IP
function getIP(){
IP=`curl -s checkip.dyndns.com | cut -d' ' -f 6 | cut -d'<' -f 1`
if [ $? -ne 0 -o -z "$IP" ]; then
yum install -y curl curl-devel
IP=`curl -s -4 ipinfo.io | grep "ip" | awk -F\" '{print $4}'`
fi
}
# is 64bit or not
function is_64bit(){
if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
return 0
else
return 1
fi
}
# Get version
function getversion(){
if [[ -s /etc/redhat-release ]];then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
fi
}
# CentOS version
function centosversion(){
local code=$1
local version="`getversion`"
local main_ver=${version%%.*}
if [ $main_ver == $code ];then
return 0
else
return 1
fi
}
# Make sure only root can run our script
function rootness(){
if [[ $EUID -ne 0 ]]; then
echo "Error:This script must be run as root!" 1>&2
exit 1
fi
}
# Disable selinux
function disable_selinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
}
# Pre-installation settings
function pre_installation_settings(){
# Display Public IP
echo "Getting Public IP address..."
getIP
echo -e "Your main public IP is\t\033[32m$IP\033[0m"
echo ""
# Choose databese
while true
do
echo "Please choose a version of the Database:"
echo -e "\t\033[32m1\033[0m. Install MySQL-5.6(recommend)"
echo -e "\t\033[32m2\033[0m. Install MySQL-5.5"
echo -e "\t\033[32m3\033[0m. Install MariaDB-5.5"
echo -e "\t\033[32m4\033[0m. Install MariaDB-10.0"
read -p "Please input a number:(Default 1) " DB_version
[ -z "$DB_version" ] && DB_version=1
case $DB_version in
1|2|3|4)
echo ""
echo "---------------------------"
echo "You choose = $DB_version"
echo "---------------------------"
echo ""
break
;;
*)
echo "Input error! Please only input number 1,2,3,4"
esac
done
# Set MySQL or MariaDB root password
echo "Please input the root password of MySQL or MariaDB:"
read -p "(Default password: root):" dbrootpwd
if [ "$dbrootpwd" = "" ]; then
dbrootpwd="root"
fi
echo ""
echo "---------------------------"
echo "Password = $dbrootpwd"
echo "---------------------------"
echo ""
if [ $DB_version -eq 1 -o $DB_version -eq 2 ]; then
# Define the MySQL data location.
echo "Please input the MySQL data location:"
read -p "(leave blank for /usr/local/mysql/data):" datalocation
[ -z "$datalocation" ] && datalocation="/usr/local/mysql/data"
echo ""
echo "---------------------------"
echo "Data location = $datalocation"
echo "---------------------------"
echo ""
elif [ $DB_version -eq 3 -o $DB_version -eq 4 ]; then
# Define the MariaDB data location.
echo "Please input the MariaDB data location:"
read -p "(leave blank for /usr/local/mariadb/data):" datalocation
[ -z "$datalocation" ] && datalocation="/usr/local/mariadb/data"
echo ""
echo "---------------------------"
echo "Data location = $datalocation"
echo "---------------------------"
echo ""
fi
# Choose PHP version
while true
do
echo "Please choose a version of the PHP:"
echo -e "\t\033[32m1\033[0m. Install PHP-5.4(recommend)"
echo -e "\t\033[32m2\033[0m. Install PHP-5.3"
echo -e "\t\033[32m3\033[0m. Install PHP-5.5"
read -p "Please input a number:(Default 1) " PHP_version
[ -z "$PHP_version" ] && PHP_version=1
case $PHP_version in
1|2|3)
echo ""
echo "---------------------------"
echo "You choose = $PHP_version"
echo "---------------------------"
echo ""
break
;;
*)
echo "Input error! Please only input number 1,2,3"
esac
done
get_char(){
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start...or Press Ctrl+C to cancel"
char=`get_char`
#Remove Packages
yum -y remove httpd*
yum -y remove mysql
yum -y remove php*
#Set timezone
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum -y install ntp
ntpdate -d cn.pool.ntp.org
StartDate=$(date);
StartDateSecond=$(date +%s);
echo "Start time: ${StartDate}";
#Install necessary tools
if [ ! -s /etc/yum.conf.bak ]; then
cp /etc/yum.conf /etc/yum.conf.bak
fi
sed -i 's:exclude=.*:exclude=:g' /etc/yum.conf
packages="wget autoconf automake bison bzip2 bzip2-devel curl curl-devel cmake cpp crontabs diffutils elinks e2fsprogs-devel expat-devel file flex freetype-devel gcc gcc-c++ gd glibc-devel glib2-devel gettext-devel gmp-devel icu kernel-devel libaio libtool-libs libjpeg-devel libpng-devel libxslt libxslt-devel libxml2 libxml2-devel libidn-devel libcap-devel libtool-ltdl-devel libc-client-devel libicu libicu-devel lynx zip zlib-devel unzip patch mlocate make ncurses-devel readline readline-devel vim-minimal sendmail pam-devel pcre pcre-devel openldap openldap-devel openssl openssl-devel perl-DBD-MySQL"
for package in $packages;
do yum -y install $package; done
}
# Download all files
function download_all_files(){
cd $cur_dir
if [ $DB_version -eq 1 ]; then
download_file "${MySQLVersion}.tar.gz"
elif [ $DB_version -eq 2 ]; then
download_file "${MySQLVersion2}.tar.gz"
elif [ $DB_version -eq 3 ]; then
download_file "${MariaDBVersion}.tar.gz"
elif [ $DB_version -eq 4 ]; then
download_file "${MariaDBVersion2}.tar.gz"
fi
if [ $PHP_version -eq 1 ]; then
download_file "${PHPVersion}.tar.gz"
elif [ $PHP_version -eq 2 ]; then
download_file "${PHPVersion2}.tar.gz"
elif [ $PHP_version -eq 3 ]; then
download_file "${PHPVersion3}.tar.gz"
fi
download_file "${ApacheVersion}.tar.gz"
download_file "${phpMyAdminVersion}.tar.gz"
download_file "${aprVersion}.tar.gz"
download_file "${aprutilVersion}.tar.gz"
download_file "${libiconvVersion}.tar.gz"
download_file "${libmcryptVersion}.tar.gz"
download_file "${mhashVersion}.tar.gz"
download_file "${mcryptVersion}.tar.gz"
download_file "${re2cVersion}.tar.gz"
download_file "${pcreVersion}.tar.gz"
download_file "${libeditVersion}.tar.gz"
if centosversion 7; then
download_file "${imapVersion}.tar.gz"
fi
}
# Download file
function download_file(){
if [ -s $1 ]; then
echo "$1 [found]"
else
echo "$1 not found!!!download now......"
if ! wget -c http://lamp.teddysun.com/files/$1;then
echo "Failed to download $1,please download it to "$cur_dir" directory manually and try again."
exit 1
fi
fi
}
# Untar all files
function untar_all_files(){
echo "Untar all files, please wait a moment..."
if [ -d $cur_dir/untar ]; then
rm -rf $cur_dir/untar
fi
mkdir -p $cur_dir/untar
for file in `ls *.tar.gz`;
do
tar -zxf $file -C $cur_dir/untar
done
echo "Untar all files completed!"
}
# Install Apache
function install_apache(){
if [ ! -d /usr/local/apache/bin ];then
#Install Apache
echo "Start Installing ${ApacheVersion}"
mv $cur_dir/untar/$aprVersion $cur_dir/untar/$ApacheVersion/srclib/apr
mv $cur_dir/untar/$aprutilVersion $cur_dir/untar/$ApacheVersion/srclib/apr-util
cd $cur_dir/untar/$ApacheVersion
./configure \
--prefix=/usr/local/apache \
--with-pcre=/usr/local/pcre \
--with-mpm=prefork \
--with-included-apr \
--enable-so \
--enable-dav \
--enable-deflate=shared \
--enable-ssl=shared \
--enable-expires=shared \
--enable-headers=shared \
--enable-rewrite=shared \
--enable-static-support \
--enable-modules=all \
--enable-mods-shared=all
make -j $Cpunum
make install
if [ $? -ne 0 ]; then
echo "Installing Apache failed, Please visit http://teddysun.com/lamp and contact."
exit 1
fi
cp -f /usr/local/apache/bin/apachectl /etc/init.d/httpd
sed -i '2a # chkconfig: - 85 15' /etc/init.d/httpd
sed -i '3a # description: Apache is a World Wide Web server. It is used to server' /etc/init.d/httpd
chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on
rm -rf /etc/httpd
ln -s /usr/local/apache/ /etc/httpd
cd /usr/sbin/
ln -fs /usr/local/apache/bin/httpd
ln -fs /usr/local/apache/bin/apachectl
cd /var/log
rm -rf httpd/
ln -s /usr/local/apache/logs httpd
groupadd apache
useradd -g apache apache
mkdir -p /data/www/default/
chmod -R 755 /data/www/default/
#Copy to config files
cp -f $cur_dir/conf/httpd2.4.conf /usr/local/apache/conf/httpd.conf
cp -f $cur_dir/conf/httpd-vhosts.conf /usr/local/apache/conf/extra/httpd-vhosts.conf
cp -f $cur_dir/conf/httpd-info.conf /usr/local/apache/conf/extra/httpd-info.conf
cp -f $cur_dir/conf/httpd-default.conf /usr/local/apache/conf/extra/httpd-default.conf
mkdir -p /usr/local/apache/conf/vhost/
touch /usr/local/apache/conf/vhost/none.conf
cp -f $cur_dir/conf/index.html /data/www/default/index.html
cp -f $cur_dir/conf/lamp.gif /data/www/default/lamp.gif
cp -f $cur_dir/conf/p.php /data/www/default/p.php
cp -f $cur_dir/conf/jquery.js /data/www/default/jquery.js
cp -f $cur_dir/conf/phpinfo.php /data/www/default/phpinfo.php
echo "${ApacheVersion} Install completed!"
else
echo "Apache had been installed!"
fi
}
# Install database
function install_database(){
if [ $DB_version -eq 1 -o $DB_version -eq 2 ]; then
install_mysql
elif [ $DB_version -eq 3 -o $DB_version -eq 4 ]; then
install_mariadb
fi
}
# Install mariadb database
function install_mariadb(){
if [ ! -d /usr/local/mariadb ];then
# Install MariaDB
cd $cur_dir/
if [ $DB_version -eq 3 ]; then
echo "Start Installing ${MariaDBVersion}"
cd $cur_dir/untar/$MariaDBVersion
elif [ $DB_version -eq 4 ]; then
echo "Start Installing ${MariaDBVersion2}"
cd $cur_dir/untar/$MariaDBVersion2
fi
/usr/sbin/groupadd mysql
/usr/sbin/useradd -s /sbin/nologin -M -g mysql mysql
# Compile MariaDB
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=$datalocation \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATEDX_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER=1
make -j $Cpunum
make install
if [ $? -ne 0 ]; then
echo "Installing MariaDB failed, Please visit http://teddysun.com/lamp and contact."
exit 1
fi
chmod +w /usr/local/mariadb
chown -R mysql:mysql /usr/local/mariadb
cp -f $cur_dir/conf/my.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
sed -i "s:^datadir=.*:datadir=$datalocation:g" /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
/usr/local/mariadb/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mariadb --datadir=$datalocation --user=mysql
cat > /etc/ld.so.conf.d/mariadb.conf<<EOF
/usr/local/mariadb/lib
/usr/local/lib
EOF
ldconfig
if is_64bit; then
ln -s /usr/local/mariadb/lib/*.* /usr/lib64/mysql
else
ln -s /usr/local/mariadb/lib/*.* /usr/lib/mysql
fi
for i in `ls /usr/local/mariadb/bin`
do
if [ ! -L /usr/bin/$i ]; then
ln -s /usr/local/mariadb/bin/$i /usr/bin/$i
fi
done
#Start mysqld service
/etc/init.d/mysqld start
/usr/local/mariadb/bin/mysqladmin password $dbrootpwd
/usr/local/mariadb/bin/mysql -uroot -p$dbrootpwd <<EOF
drop database if exists test;
delete from mysql.user where user='';
update mysql.user set password=password('$dbrootpwd') where user='root';
delete from mysql.user where not (user='root') ;
flush privileges;
exit
EOF
echo "MariaDB Install completed!"
else
echo "MariaDB had been installed!"
fi
}
# Install mysql database
function install_mysql(){
if [ ! -d /usr/local/mysql ];then
# Install MySQL
cd $cur_dir/
if [ $DB_version -eq 1 ]; then
echo "Start Installing ${MySQLVersion}"
cd $cur_dir/untar/$MySQLVersion
elif [ $DB_version -eq 2 ]; then
echo "Start Installing ${MySQLVersion2}"
cd $cur_dir/untar/$MySQLVersion2
fi
/usr/sbin/groupadd mysql
/usr/sbin/useradd -s /sbin/nologin -M -g mysql mysql
# Compile MySQL
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=complex \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=1
make -j $Cpunum
make install
if [ $? -ne 0 ]; then
echo "Installing MySQL failed, Please visit http://teddysun.com/lamp and contact."
exit 1
fi
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
cd support-files/
cp -f $cur_dir/conf/my.cnf /etc/my.cnf
cp -f mysql.server /etc/init.d/mysqld
sed -i "s:^datadir=.*:datadir=$datalocation:g" /etc/init.d/mysqld
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=$datalocation --user=mysql
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
if is_64bit; then
ln -s /usr/local/mysql/lib/*.* /usr/lib64/mysql
else
ln -s /usr/local/mysql/lib/*.* /usr/lib/mysql
fi
for i in `ls /usr/local/mysql/bin`
do
if [ ! -L /usr/bin/$i ]; then
ln -s /usr/local/mysql/bin/$i /usr/bin/$i
fi
done
#Start mysqld service
/etc/init.d/mysqld start
/usr/local/mysql/bin/mysqladmin password $dbrootpwd
/usr/local/mysql/bin/mysql -uroot -p$dbrootpwd <<EOF
drop database if exists test;
delete from mysql.user where user='';
update mysql.user set password=password('$dbrootpwd') where user='root';
delete from mysql.user where not (user='root') ;
flush privileges;
exit
EOF
echo "MySQL Install completed!"
else
echo "MySQL had been installed!"
fi
}
#Install pcre dependency
function install_pcre(){
cd $cur_dir/untar/$pcreVersion
./configure --prefix=/usr/local/pcre
make && make install
if is_64bit; then
ln -s /usr/local/pcre/lib /usr/local/pcre/lib64
fi
[ -d "/usr/local/pcre/lib" ] && export LD_LIBRARY_PATH=/usr/local/pcre/lib:$LD_LIBRARY_PATH
[ -d "/usr/local/pcre/bin" ] && export PATH=/usr/local/pcre/bin:$PATH
echo "${pcreVersion} install completed!"
}
# Install libiconv dependency
function install_libiconv(){
cd $cur_dir/untar/$libiconvVersion
./configure --prefix=/usr/local/libiconv
make && make install
echo "${libiconvVersion} install completed!"
}
# Install libmcrypt dependency
function install_libmcrypt(){
cd $cur_dir/untar/$libmcryptVersion
./configure
make && make install
echo "${libmcryptVersion} install completed!"
}
# Install mhash dependency
function install_mhash(){
cd $cur_dir/untar/$mhashVersion
./configure
make && make install
echo "${mhashVersion} install completed!"
}
# Install libmcrypt dependency
function install_mcrypt(){
/sbin/ldconfig
cd $cur_dir/untar/$mcryptVersion
./configure
make && make install
echo "${mcryptVersion} install completed!"
}
# Install re2c dependency
function install_re2c(){
cd $cur_dir/untar/$re2cVersion
./configure
make && make install
echo "${re2cVersion} install completed!"
}
# Install libedit dependency
function install_libedit(){
cd $cur_dir/untar/$libeditVersion
./configure --enable-widec
make && make install
echo "${libeditVersion} install completed!"
}
# Install imap dependency
function install_imap(){
if centosversion 7; then
cd $cur_dir/untar/$imapVersion
if is_64bit; then
make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd EXTRACFLAGS=-fPIC IP=4
else
make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd IP=4
fi
rm -rf /usr/local/imap-2007f/
mkdir /usr/local/imap-2007f/
mkdir /usr/local/imap-2007f/include/
mkdir /usr/local/imap-2007f/lib/
cp c-client/*.h /usr/local/imap-2007f/include/
cp c-client/*.c /usr/local/imap-2007f/lib/
cp c-client/c-client.a /usr/local/imap-2007f/lib/libc-client.a
echo "${imapVersion} install completed!"
fi
}
# Install PHP5
function install_php(){
if [ ! -d /usr/local/php ];then
# database compile dependency
if [ $DB_version -eq 1 -o $DB_version -eq 2 ]; then
WITH_MYSQL="--with-mysql=/usr/local/mysql"
WITH_MYSQLI="--with-mysqli=/usr/local/mysql/bin/mysql_config"
elif [ $DB_version -eq 3 -o $DB_version -eq 4 ]; then
WITH_MYSQL="--with-mysql=/usr/local/mariadb"
WITH_MYSQLI="--with-mysqli=/usr/local/mariadb/bin/mysql_config"
fi
echo "Start Installing PHP"
# ldap module dependency
if is_64bit; then
cp -rpf /usr/lib64/libldap* /usr/lib/
cp -rpf /usr/lib64/liblber* /usr/lib/
fi
# imap module dependency
if [ -f /usr/lib64/libc-client.so ];then
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
fi
if centosversion 7; then
WITH_IMAP="--with-imap=/usr/local/imap-2007f --with-imap-ssl"
else
WITH_IMAP="--with-imap --with-imap-ssl --with-kerberos"
fi
if [ $PHP_version -eq 1 ]; then
cd $cur_dir/untar/$PHPVersion
elif [ $PHP_version -eq 2 ]; then
cd $cur_dir/untar/$PHPVersion2
elif [ $PHP_version -eq 3 ]; then
cd $cur_dir/untar/$PHPVersion3
fi
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/usr/local/php/etc \
$WITH_MYSQL \
$WITH_MYSQLI \
--with-pcre-dir=/usr/local/pcre \
--with-iconv-dir=/usr/local/libiconv \
--with-mysql-sock=/tmp/mysql.sock \
--with-config-file-scan-dir=/usr/local/php/php.d \
--with-mhash=/usr \
--with-icu-dir=/usr \
--with-bz2 \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-gmp \
--with-jpeg-dir \
$WITH_IMAP \
--with-ldap \
--with-ldap-sasl \
--with-mcrypt \
--with-openssl \
--without-pear \
--with-pdo-mysql \
--with-png-dir \
--with-readline \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-bcmath \
--enable-calendar \
--enable-ctype \
--enable-dom \
--enable-exif \
--enable-ftp \
--enable-gd-native-ttf \
--enable-intl \
--enable-json \
--enable-mbstring \
--enable-pcntl \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-soap \
--enable-sockets \
--enable-tokenizer \
--enable-wddx \
--enable-xml \
--enable-zip
if [ $? -ne 0 ]; then
echo "PHP configure failed, Please visit http://teddysun.com/lamp and contact."
exit 1
fi
make && make install
if [ $? -ne 0 ]; then
echo "Installing PHP failed, Please visit http://teddysun.com/lamp and contact."
exit 1
fi
mkdir -p /usr/local/php/etc
mkdir -p /usr/local/php/php.d
if [ $PHP_version -eq 1 ]; then
mkdir -p /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525
elif [ $PHP_version -eq 2 ]; then
mkdir -p /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626
elif [ $PHP_version -eq 3 ]; then
mkdir -p /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212
fi
cp -f $cur_dir/conf/php.ini /usr/local/php/etc/php.ini
rm -f /etc/php.ini
ln -s /usr/local/php/etc/php.ini /etc/php.ini
ln -s /usr/local/php/bin/php /usr/bin/php
ln -s /usr/local/php/bin/php-config /usr/bin/php-config
ln -s /usr/local/php/bin/phpize /usr/bin/phpize
echo "PHP install completed!"
else
echo "PHP had been installed!"
fi
}
# Install phpmyadmin
function install_phpmyadmin(){
if [ ! -d /data/www/default/phpmyadmin ];then
echo "Start Installing ${phpMyAdminVersion}"
cd $cur_dir
mv untar/$phpMyAdminVersion /data/www/default/phpmyadmin
cp -f $cur_dir/conf/config.inc.php /data/www/default/phpmyadmin/config.inc.php
#Create phpmyadmin database
mysql -uroot -p$dbrootpwd < /data/www/default/phpmyadmin/examples/create_tables.sql
chmod -R 755 /data/www/default/phpmyadmin
mkdir -p /data/www/default/phpmyadmin/upload/
mkdir -p /data/www/default/phpmyadmin/save/
chown -R apache:apache /data/www/default
echo "${phpMyAdminVersion} Install completed!"
else
echo "PHPMyAdmin had been installed!"
fi
}
# Install end cleanup
function install_cleanup(){
# Start httpd service
/etc/init.d/httpd start
if [ $? -ne 0 ]; then
echo "Apache Starting failed, Please visit http://teddysun.com/lamp and contact."
exit 1
fi
cp -f $cur_dir/lamp.sh /usr/bin/lamp
cp -f $cur_dir/conf/httpd.logrotate /etc/logrotate.d/httpd
sed -i '/Order/,/All/d' /usr/bin/lamp
sed -i "/AllowOverride All/i\Require all granted" /usr/bin/lamp
# Clean up
rm -rf $cur_dir/untar
clear
# Install completed or not
if [ -s /usr/local/apache ] && [ -s /usr/local/php ] && [ -s /usr/local/mysql -o -s /usr/local/mariadb ]; then
echo ""
echo 'Congratulations, LAMP install completed!'
echo "Your Default Website: http://${IP}"
echo 'Default WebSite Root Dir: /data/www/default'
echo 'Apache Dir: /usr/local/apache'
echo 'PHP Dir: /usr/local/php'
if [ $DB_version -eq 1 -o $DB_version -eq 2 ]; then
echo "MySQL root password:$dbrootpwd"
echo "MySQL data location:$datalocation"
elif [ $DB_version -eq 3 -o $DB_version -eq 4 ]; then
echo "MariaDB root password:$dbrootpwd"
echo "MariaDB data location:$datalocation"
fi
echo -e "Installed Apache version:\033[41;37m ${ApacheVersion} \033[0m"
if [ $DB_version -eq 1 ]; then
echo -e "Installed MySQL version:\033[41;37m ${MySQLVersion} \033[0m"
elif [ $DB_version -eq 2 ]; then
echo -e "Installed MySQL version:\033[41;37m ${MySQLVersion2} \033[0m"
elif [ $DB_version -eq 3 ]; then
echo -e "Installed MariaDB version:\033[41;37m ${MariaDBVersion} \033[0m"
elif [ $DB_version -eq 4 ]; then
echo -e "Installed MariaDB version:\033[41;37m ${MariaDBVersion2} \033[0m"
fi
if [ $PHP_version -eq 1 ]; then
echo -e "Installed PHP version:\033[41;37m ${PHPVersion} \033[0m"
elif [ $PHP_version -eq 2 ]; then
echo -e "Installed PHP version:\033[41;37m ${PHPVersion2} \033[0m"
elif [ $PHP_version -eq 3 ]; then
echo -e "Installed PHP version:\033[41;37m ${PHPVersion3} \033[0m"
fi
echo -e "Installed phpMyAdmin version:\033[41;37m ${phpMyAdminVersion} \033[0m"
echo ""
echo "Start time: ${StartDate}"
echo -e "Completion time: $(date) (Use:\033[41;37m $[($(date +%s)-StartDateSecond)/60] \033[0m minutes)"
echo "Welcome to visit http://teddysun.com/lamp"
echo "Enjoy it!"
echo ""
else
echo ""
echo 'Sorry, Failed to install LAMP!';
echo 'Please visit http://teddysun.com/lamp and contact.';
fi
}
# Uninstall lamp
function uninstall_lamp(){
echo "Are you sure uninstall LAMP? (y/n)"
read -p "(Default: n):" uninstall
if [ -z $uninstall ]; then
uninstall="n"
fi
if [[ "$uninstall" = "y" || "$uninstall" = "Y" ]]; then
clear
echo "==========================="
echo "Yes, I agreed to uninstall!"
echo "==========================="
echo ""
else
echo ""
echo "============================"
echo "You cancelled the uninstall!"
echo "============================"
exit
fi
get_char(){
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo "Press any key to start uninstall LAMP...or Press Ctrl+c to cancel"
echo ""
char=`get_char`
if [[ "$uninstall" = "y" || "$uninstall" = "Y" ]]; then
/etc/init.d/httpd stop
/etc/init.d/mysqld stop
chkconfig --del httpd
chkconfig --del mysqld
rm -rf /etc/init.d/httpd /usr/local/apache /usr/sbin/httpd /usr/sbin/apachectl /var/log/httpd /var/lock/subsys/httpd /var/spool/mail/apache /etc/logrotate.d/httpd
if [ -d /usr/local/mysql ]; then
for tmp1 in `ls /usr/local/mysql/bin`
do
rm -f /usr/bin/$tmp1
done
fi
if [ -d /usr/local/mariadb ]; then
for tmp2 in `ls /usr/local/mariadb/bin`
do
rm -f /usr/bin/$tmp2
done
fi
rm -rf /usr/local/mysql /usr/local/mariadb /usr/lib64/mysql /usr/lib/mysql /etc/my.cnf /etc/init.d/mysqld /etc/ld.so.conf.d/mysql.conf /etc/ld.so.conf.d/mariadb.conf /var/lock/subsys/mysql
rm -rf /usr/local/php /usr/lib/php /usr/bin/php /usr/bin/php-config /usr/bin/phpize /etc/php.ini
rm -rf /data/www/default/phpmyadmin
rm -rf /data/www/default/xcache
rm -f /etc/pure-ftpd.conf
rm -f /usr/bin/lamp
echo "Successfully uninstall LAMP!!"
else
echo "Uninstall cancelled, nothing to do"
fi
}
# Add apache virtualhost
function vhost_add(){
# Define domain name
read -p "(Please input domains such as:www.example.com):" domains
if [ "$domains" = "" ]; then
echo "You need input a domain."
exit 1
fi
domain=`echo $domains | awk '{print $1}'`
if [ -f "/usr/local/apache/conf/vhost/$domain.conf" ]; then
echo "$domain is exist!"
exit 1
fi
# Create database or not
while true
do
read -p "(Do you want to create database?[y/N]):" create
case $create in
y|Y|YES|yes|Yes)
if [ -d /usr/local/mysql ]; then
read -p "(Please input your MySQL root password):" mysqlroot_passwd
mysql -uroot -p$mysqlroot_passwd <<EOF
exit
EOF
if [ $? -eq 0 ]; then
echo "MySQL root password is correct.";
else
echo "MySQL root password incorrect! Please check it and try again!"
exit 1
fi
elif [ -d /usr/local/mariadb ]; then
read -p "(Please input your MariaDB root password):" mysqlroot_passwd
mysql -uroot -p$mysqlroot_passwd <<EOF
exit
EOF
if [ $? -eq 0 ]; then
echo "MariaDB root password is correct.";
else
echo "MariaDB root password incorrect! Please check it and try again!"
exit 1
fi
fi
read -p "(Please input the database name):" dbname
read -p "(Please set the password for user $dbname):" mysqlpwd
create=y
break
;;
n|N|no|NO|No)
echo "Not create database, you entered $create"
create=n
break
;;
*) echo Please input only y or n
esac
done
# Create database
if [ "$create" == "y" ];then
mysql -uroot -p$mysqlroot_passwd <<EOF
CREATE DATABASE IF NOT EXISTS \`$dbname\`;
GRANT ALL PRIVILEGES ON \`$dbname\` . * TO '$dbname'@'localhost' IDENTIFIED BY '$mysqlpwd';
GRANT ALL PRIVILEGES ON \`$dbname\` . * TO '$dbname'@'127.0.0.1' IDENTIFIED BY '$mysqlpwd';
GRANT ALL PRIVILEGES ON \`phpmyadmin\` . * TO '$dbname'@'localhost' IDENTIFIED BY '$mysqlpwd';
GRANT ALL PRIVILEGES ON \`phpmyadmin\` . * TO '$dbname'@'127.0.0.1' IDENTIFIED BY '$mysqlpwd';
FLUSH PRIVILEGES;
EOF
fi
# Define website dir
webdir="/data/www/$domain"
DocumentRoot="$webdir/web"
logsdir="$webdir/logs"
mkdir -p $DocumentRoot $logsdir
chown -R apache:apache $webdir
# Create vhost configuration file
cat >/usr/local/apache/conf/vhost/$domain.conf<<EOF
<virtualhost *:80>
ServerName $domain
ServerAlias $domains
DocumentRoot $DocumentRoot
CustomLog $logsdir/access.log combined
DirectoryIndex index.php index.html
<Directory $DocumentRoot>
Options +Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from All
php_admin_value open_basedir $DocumentRoot:/tmp
</Directory>
</virtualhost>
EOF
/etc/init.d/httpd restart > /dev/null 2>&1
echo "Successfully create $domain vhost"
echo "######################### information about your website ############################"
echo "The DocumentRoot:$DocumentRoot"
echo "The Logsdir:$logsdir"
[ "$create" == "y" ] && echo "database name and user:$dbname, password:$mysqlpwd"
}
# Remove apache virtualhost
function vhost_del(){
read -p "(Please input a domain you want to delete):" vhost_domain
if [ "$vhost_domain" = "" ]; then
echo "You need input a domain."
exit 1
fi
echo "---------------------------"
echo "vhost account = $vhost_domain"
echo "---------------------------"
echo ""
get_char(){
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}