标签:lamp
#!/bin/bash/
#Auto setup LAMP,download software by internet.
#by lrj
#2016-3-23
#定义各自变量及目录
PUBLIC_DIR=/data/software/lamp/ #下载的源码包放这里
#Apache define path variable
H_FILES=httpd-2.2.31.tar.bz2
H_FILES_DIR=httpd-2.2.31
H_URL=http://mirrors.cnnic.cn/apache/httpd/ #中国互联网络信息中心开源镜像站(apache开源软件镜像,包含hadoop、hbase等资源)
H_PREFIX=/usr/local/apache2/
#MySQL define path variable
M_FILES=mysql-5.5.48.tar.gz
M_FILES_DIR=mysql-5.5.48
M_URL=http://mirrors.sohu.com/mysql/MySQL-5.5/
M_PREFIX=/usr/local/mysql/
#PHP define path variable
P_FILES=php-5.3.28.tar.gz
P_FILES_DIR=php-5.3.28
P_URL=http://mirrors.sohu.com/php/ #sohu的源,比较多资源
P_PREFIX=/usr/local/php5/
#打印菜单
echo -e " \033[32m --------------------------------------------------------\033[0m "
echo
if [ -z "$1" ];then
echo -e " \033[36m Please select Install Memu follow:\033[0m "
echo -e " \033[32m 1)编译安装Apache服务器\033[0m "
echo -e " 2)编译安装MySQL服务器 "
echo -e " 3)编译安装PHP服务器 "
echo -e " 4)配置index.php,启动LAMP服务 "
echo -e " \033[31m Usage: { /bin/sh $0 1|2|3|4|help }\033[0m "
exit
fi
if [[ "$1" -eq "help" ]];then
echo -e " \033[36m Please select Install Memu follow:\033[0m "
echo -e " \033[32m 1)编译安装Apache服务器\033[0m "
echo -e " 2)编译安装MySQL服务器 "
echo -e " 3)编译安装PHP服务器 "
echo -e " 4)配置index.php,启动LAMP服务 "
echo -e " \033[31m Usage: { /bin/sh $0 1|2|3|4|help }\033[0m "
exit
fi
###################################################
#安装Apache服务
if [[ "$1" -eq "1" ]];then
wget -cP $PUBLIC_DIR $H_URL/$H_FILES && cd $PUBLIC_DIR && tar -jvxf $H_FILES && cd $H_FILES_DIR && ./configure --prefix=$H_PREFIX
if [ $? -eq 0 ];then
make && make install
echo -e " \033[32m --------------------------------------------------------\033[0m "
echo -e " \033[32m The $H_FILES_DIR server install success !\033[0m "
else
echo -e " \033[32m The $H_FILES_DIR make or make install error,please checking..... \033[0m "
exit 0
fi
fi
#安装MySQL服务
if [[ "$1" -eq "2" ]];then
useradd mysql -s /bin/false;
wget -cP $PUBLIC_DIR $M_URL/$M_FILES && cd $PUBLIC_DIR && tar -zvxf $M_FILES && yum -y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool* cmake -y &&
cd $PUBLIC_DIR$M_FILES_DIR/ &&ccmake . -DCMAKE_INSTALL_PREFIX=$M_PREFIX \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DYSQL_TCP_PORT=3306 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.scok \ -DMYSQL_USER=mysql \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_DEBUG=0 \ -DWITH_BIG_TABLES=1 \ -DWITH_XTRADB_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_EXTRA_CHARSET=1 \
if [ $? -eq 0 ];then
make && make install
if [ $? -eq 0 ];then
/bin/cp $M_PREFIX/support-files/my-small.cnf /etc/my.cnf
/bin/cp $M_PREFIX/support-files/mysql.server /etc/init.d/mysqld
/bin/chmod +x /etc/init.d/mysqld
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
else
echo -e " \033[32m The $M_FILES_DIR make or make install error,please checking..... \033[0m "
exit 0
fi
echo -e " \033[32m --------------------------------------------------------\033[0m "
echo -e " \033[32m The $M_FILES_DIR server install success !\033[0m "
else
echo -e " \033[32m The $M_FILES_DIR make or make install error,please checking..... \033[0m "
exit 0
fi
fi
#安装PHP服务
if [[ "$1" -eq "3" ]];then
wget -cP $PUBLIC_DIR $P_URL/$P_FILES && cd $PUBLIC_DIR && tar -zvxf $P_FILES && yum -y install libmcrypt libiconv mcrypt mhash &&cd $PUBLIC_DIR$P_FILES_DIR&& ./configure --prefix=$P_PREFIX --with-config-file-path=/etc/ --with-mysql=$M_PREFIX --with-apxs2=$H_PREFIX/bin/apxs --with-mhash --with-zlib --with-gettext --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-bcmath --enable-mbstring --enable-zip --enable-sockets --without-pear
if [ $? -eq 0 ];then
make && make install
echo -e " \033[32m --------------------------------------------------------\033[0m "
echo -e " \033[32m The $P_FILES_DIR server install success !\033[0m "
else
echo -e " \033[32m The $P_FILES_DIR make or make install error,please checking..... \033[0m "
exit 0
fi
fi
#配置测试LAMP服务
if [[ "$1" -eq "4" ]];then
sed -i ‘s%DirectoryIndex index.html%DirectoryIndex index.php index.html%g‘ $H_PREFIX/conf/httpd.conf
sed -i ‘s%#ServerName www.example.com:80%ServerName www.example.com:80%g‘ $H_PREFIX/conf/httpd.conf
echo " AddType application/x-httpd-php .php .phtml" >> $H_PREFIX/conf/httpd.conf
echo " AddType application/x-httpd-php-source .phps" >> $H_PREFIX/conf/httpd.conf
$H_PREFIX/bin/httpd -t
echo " $H_PREFIX/bin/apachectl start " >> etc/rc.local
IP=`ifconfig eth1|grep "Bcast"|awk ‘{print $2}‘|cut -d: -f2`
echo "You can access http://$IP/;Please open brower testing..."
cat >$H_PREFIX/htdocs/index.php << EOF
<?php
phpinfo();
?>
EOF
fi
注:编写shell格式很重要,建议一定要用vim下编写,如在其它文本文件编辑器上编写的,要在vim模式编辑查看,特别是编译参数方面的书写,或做语法检查,减少错误。
标签:lamp
原文地址:http://9625010.blog.51cto.com/9615010/1757420