#!/bin/bash # By Stranded 2015-08-20 CMA_V=cmake-2.8.6 APA_V=httpd-2.2.15 MYS_V=mysql-5.5.22 LIB_V=libmcrypt-2.5.8 MHA_V=mhash-0.9.9.9 MCR_V=mcrypt-2.6.8 PHP_V=php-5.3.28 apache(){ # 判断是否有RPM方式安装的httpd、httpd-manual软件包,如果有则卸载 if [ $(rpm -qa | grep httpd) ] || [ $(rpm -qa | grep httpd-manual) ] then rpm -e httpd --nodeps rpm -e httpd-manual --nodeps else echo "httpd is not rpm" fi # httpd软件包解压、配置、编译、安装 tar -zxvf /root/$APA_V\.tar.gz -C /usr/src/ cd /usr/src/$APA_V/ ./configure --prefix=/usr/local/httpd --enable-so --enable-charset-lite --enable-cgi --enable-rewrite --disable-access make && make install # 判断apache是否安装成功 if [ -e /usr/local/httpd ] then echo "Apache install Successfull" cd - fi } mysql(){ # 判断是否有RPM方式安装的mysql、mysql-server软件包,如果有则卸载 if [ $(rpm -qa | grep mysql) ] || [ $(rpm -qa | grep mysql-server) ] then rpm -e mysql rpm -e mysql-server else echo "mysql is not rpm" fi # 判断是否配置本地yum源,并且是否已经挂载光盘 if [ ! -z /mnt ] then mount /dev/cdrom /mnt else echo "/mnt is exitis" fi if [ ! -e /etc/yum.repos.d/local.repo ] then cat <<END >/etc/yum.repo.s/local.repo [local] name=local baseurl=file:///mnt gpgcheck=0 enabled=1 END fi # 安装ncurses-devel、bison(依赖包),解决报错问题 yum -y install ncurses-devel bison # cmake(基础环境,类似于vc++ 2005),解压、配置、编译、安装 tar -zxvf /root/$CMA_V\.tar.gz -C /usr/src/ cd /usr/src/$CMA_V/ ./configure && gmake && gmake install # mysql软件包解压,配置,编译,安装 tar -zxvf /root/$MYS_V\.tar.gz -C /usr/src/ cd /usr/src/$MYS_V/ rm -rf CMakeCache.txt cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYCONFDIR=/etc/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all make && make install # 判断mysql是否安装完成 if [ -e /usr/local/mysql ] then echo "Mysql install Successfull" cd - fi } php(){ # 判断是否有RPM方式安装的php及其相关依赖包,如果有则卸载 EAR_P=$(cat /root/earse_php) rpm -qa | grep php | awk ‘{print $1}‘ >/root/earse_php if [ ! -z /root/earse_php ] then for i in $EAR_P do rpm -e $i done else echo "php is not rpm" fi # 判断是否配置本地yum源,并且是否已经挂载光盘 if [ ! -z /mnt ] then mount /dev/cdrom /mnt else echo "/mnt is exitis" fi if [ ! -e /etc/yum.repos.d/local.repo ] then cat <<END >/etc/yum.repo.s/local.repo [local] name=local baseurl=file:///mnt gpgcheck=0 enabled=1 END fi # 安装依赖包libxml2-devel,解决报错问题 yum -y install libxml2-devel # 安装libmcrypt软件包,并做软链接 tar -zxvf /root/$LIB_V\.tar.gz -C /usr/src/ cd /usr/src/$LIB_V/ ./configure && make && make install ln -s /usr/local/lib/libmcrypt.* /usr/lib/ # 安装mhash软件包,并作软链接 tar -zxvf /root/$MHA_V\.tar.gz -C /usr/src/ cd /usr/src/$MHA_V/ ./configure && make && make install ln -s /usr/local/lib/mhash* /usr/lib/ # 安装mcrypt软件包,并设置LD_LIBRARY_PATH变量(解决环境问题) tar -zxvf /root/$MCR_V\.tar.gz -C /usr/src/ cd /usr/src/$MCR_V/ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./configure && make && make install # php软件包解压,配置、编译、安装 tar -zxvf /root/$PHP_V\.tar.gz -C /usr/src/ cd /usr/src/$PHP_V/ ./configure --prefix=/usr/local/php/ --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php/ --enable-mbstring make && make install # 确认php是否成功安装 if [ -e /usr/local/php ] then echo "PHP install Successfull" cd - fi } case "$1" in apache) apache ;; mysql) mysql ;; php) php ;; lamp) apache mysql php ;; *) echo ""$0" is install { lamp | apache | mysql | php }" ;; esac
本文出自 “Painting” 博客,请务必保留此出处http://painting.blog.51cto.com/10476797/1688028
原文地址:http://painting.blog.51cto.com/10476797/1688028