LAMP及LNMP测试环境快速构建(yum版)
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
#########################################################################
# File Name: lamp_yum_install.sh
# Author: mads
# Mail: 1455975151@qq.com
# Created Time: 2015年10月09日 星期五 06时13分20秒
# Description : this is scripts use to lamp install
# Version : v1.0
#########################################################################
#!/bin/bash
. /etc/init.d/functions
RED_COLOR='\E[1;31m'
GREEN_COLOR='\E[1;32m'
YELLOW_COLOR='\E[1;33m'
BLUE_COLOR='\E[1;34m'
RES='\E[0m'
apache_install(){
yum -y install httpd httpd-devel
cp /etc/httpd/conf/httpd.conf{,.`date +%Y%m%d`}
sed -i s'/#ServerName www.example.com:80/ServerName 127.0.0.1:80/g' /etc/httpd/conf/httpd.conf
/etc/init.d/httpd start
chkconfig httpd on
}
mysql_install(){
yum -y install mysql mysql-server mysql-devel
/etc/init.d/mysqld start
/usr/bin/mysqladmin -u root password '123456'
chkconfig mysqld on
}
php_install(){
yum -y install php php-mysql gd php-gd gd-devel php-xml php-common php-mbstring php-ldap php-pear php-xmlrpc php-imap
}
lamp_test(){
/etc/init.d/httpd restart
cat>>/var/www/html/index.php<<EOF
<?php
phpinfo();
?>
EOF
cat >/var/www/html/mysql.php<<EOF
<?php
//\$link_id=mysql_connect('主机名','用户','密码');
\$link_id=mysql_connect('localhost','root','123456') or mysql_error();
if(\$link_id){
echo "mysql successful by mads!";
}else{
echo mysql_error();
}
?>
EOF
}
main(){
apache_install
mysql_install
php_install
lamp_test
}
main
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
#########################################################################
# File Name: lnmp_yum_install.sh
# Author: mads
# Mail: 1455975151@qq.com
# Created Time: 2015年10月09日 星期五 06时17分02秒
# Description : this is scripts use to lnmp install
# Version : v1.0
#########################################################################
#!/bin/bash
. /etc/init.d/functions
RED_COLOR='\E[1;31m'
GREEN_COLOR='\E[1;32m'
YELLOW_COLOR='\E[1;33m'
BLUE_COLOR='\E[1;34m'
RES='\E[0m'
nginx_install(){
yum -y install nginx
/etc/init.d/nginx start
chkconfig nginx on
}
mysql_install(){
yum -y install mysql mysql-server mysql-devel
/etc/init.d/mysqld start
/usr/bin/mysqladmin -u root password '123456'
chkconfig mysqld on
}
php_install(){
yum install -y php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm
/etc/init.d/php-fpm start
chkconfig php-fpm on
#nginx setup
cp /etc/nginx/conf.d/default.conf{,.`date +%Y%m%d`}
sed -i '17s/index.html/index.php index.html/g' /etc/nginx/conf.d/default.conf
sed -i '39,46s/#//g' /etc/nginx/conf.d/default.conf
sed -i '44s/\/scripts/$document_root/g' /etc/nginx/conf.d/default.conf
#php-fpm setup
cp /etc/php-fpm.d/www.conf{,.`date +%Y%m%d`}
sed -i 's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf
sed -i 's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf
}
lnmp_test(){
/etc/init.d/nginx restart
cat>>/usr/share/nginx/html/index.php<<EOF
<?php
phpinfo();
?>
EOF
cat >/usr/share/nginx/html/mysql.php<<EOF
<?php
//\$link_id=mysql_connect('主机名','用户','密码');
\$link_id=mysql_connect('localhost','root','123456') or mysql_error();
if(\$link_id){
echo "mysql successful by mads!";
}else{
echo mysql_error();
}
?>
EOF
}
main(){
nginx_install
mysql_install
php_install
lnmp_test
}
main
页:
[1]