1)系统环境介绍
     Centos 5.8 64位
     Apache:httpd-2.4.4.tar.gz
     PHP:   php-5.4.17.tar.gz 
     Mysql: mysql-5.6.12.tar.gz

2)安装脚本

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH
#INFO函数定义输出字体颜色,echo -e 表示保持字符串的特殊含义,$1表示字体颜色编号,$2表示等待程序执行时间,$3表示echo输出内容。
function INFO()
{echo -e "\e[$1;49;1m: $3 \033[39;49;0m"sleep "$2"echo ""
}
#非root用户不能执行该脚本
if  [ "$UID" != 0 ];thenecho " "INFO 35 "0" "Must be root ro run this script."exit 1
fi
#USAGE函数定义脚本用法,可反复调用,basename其实就是脚本名,\n表示换行。
function USAGE()
{INFO 35 "0.1" "Please see the script of the usage:"basename=$(basename "$0")INFO \36 "0" \"$(echo -e "Usage: \n\n./$basename (apache|mysql|php) install \n./$basename apache (start|stop|restart) \n./$basename mysql (start|stop|restart)\n")"
}
#YUM_INSTALL函数安装依赖包,可反复调用,$@表示所有参数都分别被双引号引住"$1","$2",而$*表示所有这些参数都被双引号引住"$1$2"
function YUM_INSTALL()
{for a in $@; doINFO 32 1 "Install depend on the [ $a ]"yum -y install $a || exit 1if [ $a = "libXpm-devel" ]; thenln -s /usr/lib/x86_64-linux-gnu/libXpm.so /usr/lib/libXpm.so#elif [ $a = "libsasl2-dev" ]; then#     cp /usr/lib/x86_64-linux-gnu/libldap* /usr/lib/fidone
}
#INSTALL函数定义安装程序,可一反复调用,安装apache程序的时候要先安装3个依赖包,在安装mysql的时候要用cmake编译。$1表示要安装的程序,$2表示yum安装对应的依赖包,$3表示程序解压后的目录,$4表示程序源码包。
function INSTALL()
{YUM_INSTALL "$2" && cd $SOURCE_PATH[ -d $3 ] && rm -r $3; INFO 31 4 "Unpack the $4 installation package......"tar zxvf $4; cd $3 ; pwd ; INFO 32 4 "Configure the $1......"if [ $1 = apache ];thencp -rf ../apr-1.4.8 srclib/aprcp -rf ../apr-util-1.5.2 srclib/apr-util./configure $5 || exit 1elif [ $1 = mysql ];thencmake $5 || exit 1elif [ $1 = openssl ];then./config $5 || exit 1elif [ $1 = libpng ];thencp scripts/makefile.linux makefileelif [ $1 = jpegsrc.v6b.tar.gz ];thencp /usr/share/libtool/config.guess  ./cp /usr/share/libtool/config.sub ././configure $5 || exit 1mkdir -p  /usr/local/env/jpeg/binmkdir -p  /usr/local/env/jpeg/libmkdir -p  /usr/local/env/jpeg/includemkdir -p /usr/local/env/jpeg/man/man1else./configure $5 || exit 1fiINFO 36 3 "Compile $1......"make || exit 1 && INFO 34 4 "Install $1......" ; make install && INFO 33 4 "$1 installation is successful......"if [ $1 = mysql ];thenecho $INSTALL_PATH/mysql/lib/mysql >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = libiconv ];thenecho "/usr/local/env/libiconv/lib" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = libxml2 ];thenecho "/usr/local/env/libxml2/lib" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = libmcrypt ];thenecho "/usr/local/env/libmcrypt/lib" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = mhash ];thenecho "/usr/local/lib" >> /etc/ld.so.confecho "/usr/local/lib64" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = gettext ];thenecho "/usr/local/env/gettext/lib" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = gd ];thensed -i '27 a void (*data);' /usr/local/env/gd/include/gd_io.hecho "/usr/local/env/gd/lib" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = freetype ];thenecho "/usr/local/env/freetype/lib" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add $1 library file to ld.so.conf......"fiif [ $1 = jpegsrc.v6b.tar.gz ];thenecho "/usr/local/env/jpeg/lib" >> /etc/ld.so.conf/sbin/ldconfig && INFO 33 4 "Add jpeg library file to ld.so.conf......"fi
}
#SERVICE函数定义程序启动,关闭,重启。
function SERVICE()
{if [ $1 = apache -a $2 = start ]; then$INSTALL_PATH/$1/bin/apachectl -k start && \INFO 33 "2.5" "Apache startup success......"exitelif [ $1 = apache -a $2 = stop ]; then$INSTALL_PATH/$1/bin/apachectl -k stop && \INFO 31 "2.5" "Apache has stopped......"exitelif [ $1 = apache -a $2 = restart ]; then$INSTALL_PATH/$1/bin/apachectl -k stop ; sleep 2INFO 31 "2.5" "Apache has stopped......"$INSTALL_PATH/$1/bin/apachectl -k start && \INFO 34 "2.5" "Apache has restarted......"exitelif [ $1 = mysql -a $2 = start ]; then/bin/bash $INSTALL_PATH/$1/bin/mysqld_safe --defaults-file=$INSTALL_PATH/$1/my.cnf 2>&1 > /dev/null &INFO 33 "2.5" "Mysql startup success......"echo -e "$(netstat -ntpl|grep "/:::3306")"exitelif [ $1 = mysql -a $2 = stop ]; thenkill $(netstat -ntpl|awk '/:::3306/{print $NF}'|awk -F '/' '{print $1}') && \INFO 31 "2.5" "Mysql has stopped......"exitelif [ $1 = mysql -a $2 = restart ]; thenkill $(netstat -ntpl|awk '/:::3306/{print $NF}'|awk -F '/' '{print $1}') && \INFO 31 "3" "Mysql has stopped......"/bin/bash $INSTALL_PATH/$1/bin/mysqld_safe --defaults-file=$INSTALL_PATH/$1/my.cnf 2>&1 > /dev/null &INFO 34 "2.5" "Mysql has restarted......"exitfi
}
#CONFIG_MYSQL函数用来定义mysql的配置。
function CONFIG_MYSQL()
{INFO 32 3 "Configure the mysql......"groups mysql || groupadd mysql && id mysql || useradd -g mysql mysqlcd $INSTALL_PATH/mysql ; pwd./scripts/mysql_install_db \--user=mysql \--basedir=$INSTALL_PATH/mysql/ \--datadir=$INSTALL_PATH/mysql/data/ \--defaults-file=$INSTALL_PATH/mysql/my.cnfecho ""; sleep 3cp $(dirname $SOURCE_PATH)/conf/my.cnf ./INFO 35 2 "Mysql configuration is complete......"
}
#CONFIG_HTTPD函数用来配置apache。
function CONFIG_HTTPD()
{INFO 32 3 "Configure the apache......"echo -e "<?php\nphpinfo();\n?>" > $INSTALL_PATH/apache/htdocs/phpinfo.phpsed -i 's/^\ \ \ \ AddType application\/x-gzip .gz .tgz$/&\n\ \ \ \ AddType application\/x-httpd-php .php/' \$INSTALL_PATH/apache/conf/httpd.confsed -i 's/^#ServerName www.example.com:80$/&\nServerName 127.0.0.1:80/' $INSTALL_PATH/apache/conf/httpd.confINFO 35 2 "Apache configuration is complete......"
}
#CONFIG_PHP函数用来配置php。
function CONFIG_PHP()
{INFO 32 3 "Configure the php......"cp $SOURCE_PATH/$1/php.ini-development $INSTALL_PATH/php5/etc/php.iniINFO 35 2 "Php configuration is complete......"
}
#INSTALL_BRANCH函数定义程序安装,${TAR_NAME[@]}是shell脚本中数组写法,即取全部元素,即TAR_NAME里面的所有包,SERVER_NAME表示包的名称,COMPILE_DIR表示包名+版本后,即解压后的目录名。
function INSTALL_BRANCH()
{for i in ${TAR_NAME[@]}; doSERVER_NAME=$(echo $i|awk -F "-[0-9]" '{print $1}')COMPILE_DIR=$(echo $i|awk -F ".tar.gz" '{print $1}')if [ $1 = $SERVER_NAME -a $1 = apr ]; thenINSTALL apr " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/apr"elif [ $1 = $SERVER_NAME -a $1 = apr-util ];thenINSTALL apr-util " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/apr-util --with-apr=/usr/local/env/apr"elif [ $1 = $SERVER_NAME -a $1 = pcre ]; thenINSTALL pcre " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/pcre"elif [ $1 = $SERVER_NAME -a $1 = httpd ]; thenINSTALL apache "$HTTP_YUM" "$COMPILE_DIR" "$i" "$HTTP_PARAMETERS"CONFIG_HTTPDelif [ $1 = $SERVER_NAME -a $1 = mysql ]; thenINSTALL mysql "$MYSQL_YUM" "$COMPILE_DIR" "$i" "$MYSQL_PARAMETERS"CONFIG_MYSQLelif [ $1 = $SERVER_NAME -a $1 = libiconv ]; thenINSTALL libiconv " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/libiconv"elif  [ $1 = $SERVER_NAME -a $1 = libxml2 ]; thenINSTALL libxml2 " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/libxml2 --with-iconv=/usr/local/env/libiconv"elif  [ $1 = $SERVER_NAME -a $1 = curl ]; then       INSTALL curl " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/curl --enable-utf8"elif  [ $1 = $SERVER_NAME -a $1 = libmcrypt ]; then                                  INSTALL libmcrypt " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/libmcrypt"elif  [ $1 = $SERVER_NAME -a $1 = mhash ]; thenINSTALL mhash " " "$COMPILE_DIR" "$i" " "elif  [ $1 = $SERVER_NAME -a $1 = mcrypt ]; thenINSTALL mcrypt " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/mcrypt \--with-libmcrypt-prefix=/usr/local/env/libmcrypt \--with-libiconv-prefix=/usr/local/env/libiconv"elif   [ $1 = $SERVER_NAME -a $1 = gettext ]; thenINSTALL gettext " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/gettext \--with-libiconv-prefix=/usr/local/env/libiconv \--with-libxml2-prefix=/usr/local/env/libxml2"elif  [ $1 = $SERVER_NAME -a $1 = freetype ]; thenINSTALL freetype " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/freetype"elif  [ $1 = $SERVER_NAME -a $1 = jpegsrc.v6b.tar.gz ]; thenCOMPILE_DIR="jpeg-6b"INSTALL jpegsrc.v6b.tar.gz " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/jpeg --enable-shared --enable-static"elif  [ $1 = $SERVER_NAME -a $1 = libpng ]; thenINSTALL libpng " " "$COMPILE_DIR" "$i" " "elif  [ $1 = $SERVER_NAME -a $1 = gd ]; thenINSTALL gd " " "$COMPILE_DIR" "$i" "--prefix=/usr/local/env/gd --with-png=/usr \--with-freetype=/usr/local/env/freetype \--with-jpeg=/usr/local/env/jpeg  --with-fontconfig=/usr --with-xpm=/usr"elif  [ $1 = $SERVER_NAME -a $1 = openssl ]; thenINSTALL openssl " " "$COMPILE_DIR" "$i" "-fPIC --prefix=/usr/local/env/openssl shared"elif  [ $1 = $SERVER_NAME -a $1 = php ]; thenINSTALL php5 "$PHP5_YUM" "$COMPILE_DIR" "$i" "$PHP5_PARAMETERS"CONFIG_PHP "$COMPILE_DIR"breakelsecontinuefidone
}
#MOD_CASE函数用KASE定义选择安装程序。
function MOD_CASE()
{if [[ $1 =~ apache|mysql|php ]] && [[ $2 =~ install|start|stop|restart ]]; thenINFO 32 "1.5" "Input the correct,according to the option to perform related operations......"echo ""if [ $2 = install ]; thencase "$1 $2" in"apache install")INFO 35 "2.5" "Start to $1 the $2......"INSTALL_BRANCH aprINSTALL_BRANCH apr-utilINSTALL_BRANCH pcreINSTALL_BRANCH httpd;;"mysql install")INFO 35 "2.5" "Start to $1 the $2......"INSTALL_BRANCH mysql;;"php install")INFO 35 "2.5" "Start to $1 the $2......"export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib:/usr/local/lamp/mysql/libINSTALL_BRANCH libiconvINSTALL_BRANCH libxml2INSTALL_BRANCH curlINSTALL_BRANCH libmcryptINSTALL_BRANCH mhashINSTALL_BRANCH mcryptINSTALL_BRANCH gettextINSTALL_BRANCH freetypeINSTALL_BRANCH jpegsrc.v6b.tar.gzINSTALL_BRANCH libpngINSTALL_BRANCH gdINSTALL_BRANCH openssl#INSTALL_BRANCH httpd && INSTALL_BRANCH mysql && INSTALL_BRANCH phpINSTALL_BRANCH php;;esacelseSERVICE $1 $2fielseINFO 31 1 "Input error, please try again!"INPUTfi
}
#LAMP程序安装的目录
INSTALL_PATH="/usr/local/lamp"
#源码包存放目录
SOURCE_PATH="$(cd $(dirname $0); pwd)/install_tar"
#源码包列表
TAR_NAME=(httpd-2.4.4.tar.gz mysql-5.6.12.tar.gz php-5.4.17.tar.gz apr-1.4.8.tar.gz apr-util-1.5.2.tar.gz pcre-8.10.tar.gz freetype-2.4.0.tar.gz jpegsrc.v6b.tar.gz libxml2-2.7.2.tar.gz mhash-0.9.9.9.tar.gz mcrypt-2.6.8.tar.gz gd-2.0.35.tar.gz libiconv-1.14.tar.gz gettext-0.18.tar.gz libmcrypt-2.5.8.tar.gz openssl-0.9.8p.tar.gz curl-7.32.0.tar.gz libpng-1.2.33.tar.gz)
#Apache,Mysql,PHP yum安装依赖包
HTTP_YUM="build-essential libapr1 libapr1-dev libaprutil1 libaprutil1-dev gettext gettext-devel"
MYSQL_YUM="cmake libncurses5 libncurses5-dev bison"
PHP5_YUM="libxml2 libxml2-devel openssl libjpeg-devel bzip2 libXpm-devel libmcrypt-devel"
#Apache编译参数
HTTP_PARAMETERS="\
--prefix=$INSTALL_PATH/apache \
--enable-module=so \
--enable-module=rewrite \
--enable-shard=rewrite \
--enable-shared=max \
--with-apr=/usr/local/env/apr \
--with-apr-util=/usr/local/env/apr-util \
--with-pcre=/usr/local/env/pcre \
--with-included-apr \
"
#mysql编译参数
MYSQL_PARAMETERS="\
-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH/mysql \
-DYSQL_TCP_PORT=3306 \
-DMYSQL_DATADIR=$INSTALL_PATH/mysql/data \
-DMYSQL_UNIX_ADDR=$INSTALL_PAHT/mysql/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_DEBUG=0 \
"
#PHP编译参数
PHP5_PARAMETERS="\
--prefix=$INSTALL_PATH/php5 \
--with-config-file-path=$INSTALL_PATH/php5/etc \
--with-mysql=$INSTALL_PATH/mysql \
--with-apxs2=$INSTALL_PATH/apache/bin/apxs \
--with-mysqli=$INSTALL_PATH/mysql/bin/mysql_config \
--with-iconv=/usr/local/env/libiconv \
--with-jpeg-dir=/usr/local/env/jpeg  \
--with-png-dir=/usr \
--with-libxml-dir=/usr/local/env/libxml2  \
--with-pdo-mysql \
--with-zlib \
--with-curl=/usr/local/env/curl \
--with-curlwrappers \
--with-mcrypt=/usr/local/env/libmcrypt \
--with-gd=/usr/local/env/gd  \
--with-openssl=/usr/local/env/openssl \
--with-mhash=/usr \
--with-xmlrpc \
--with-xpm-dir \
--with-freetype-dir=/usr/local/env/freetype \
--with-zlib-dir \
--with-ldap \
--with-ldap-sasl \
--with-pcre-regex \
--with-gettext=/usr/local/env/gettext \
--with-ncurses \
--enable-shared \
--enable-xml \
--enable-safe-mode \
--enable-track-vars \
--enable-magic-quotes \
--enable-bcmath \
--enable-sysvsem \
--enable-sysshm \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--enable-zip \
--enable-soap \
--enable-discard-path \
--enable-force-cgi-redirect \
--enable-pdo \
--enable-calendar \
--enable-exif \
--enable-zend-multibyte \
"
#--disable-rpath
#脚本调用帮助程序
if [ $# = 2 ]thenINFO 33 "1.5" "please wait......"echo ""MOD_CASE "$1" "$2"elseUSAGEexit 1
fi

3)脚本的用法

http://yunpan.cn/cZEAF53PLTqRg    访问密码 309b

#下载安装脚本和源码包
wget https://sourceforge.net/projects/opensourcefile/files/
Install_Centos_LAMP_v.0.1.zip/download --no-check-certificate
unzip Install_Centos_LAMP_v.0.1.zip
chmod +x Install_Centos_LAMP_v.0.1.sh
#查看脚本的用法,可通过该脚本安装apache,mysql,php,启动,关闭和重启apache和mysql。
./Install_Centos_LAMP_v.0.1.sh
: Please see the script of the usage:
: Usage:
./Install_Centos_LAMP_v.0.1.sh (apache|mysql|php) install
./Install_Centos_LAMP_v.0.1.sh apache (start|stop|restart)
./Install_Centos_LAMP_v.0.1.sh mysql (start|stop|restart)

本文转自:http://sfzhang88.blog.51cto.com/4995876/1281640

转载于:https://blog.51cto.com/hao360/1623750

Centos 上面用Shell脚本一键安装LAMP环境相关推荐

  1. shell脚本一键安装nginx

        使用shell脚本一键安装Nginx 操作环境Centos7,联网进行安装. 代码如下: #!/bin/bash #this is nginx.sh #date 2018.10.6 [ $(i ...

  2. shell脚本一键安装二进制Apache

    转载来源 :shell脚本一键安装二进制Apache : http://www.178linux.com/23401 安装背景:用的一台最小化安装的centos6. 编译安装安装的必备安装gcc,gc ...

  3. Ubuntu一键安装LAMP环境

    ubuntu是一款以桌面应用为主的开源linux操作系统,作为初学者学习linux操作系统,也更为简单和容易上手.在Ubuntu上搭建lamp系统的方式有很多,这里就介绍一种最简单高效的安装方法: a ...

  4. centos下一键安装lamp环境,快捷,方便

    http://www.centos.bz/lamp/ 适用环境: 系统支持:CentOS-5 (32bit/64bit).CentOS-6 (32bit/64bit) 内存要求:≥256M 安装了什么 ...

  5. mysql 一键安装 linux_linux下mysql8 shell脚本一键安装

    1:下载mysql8文件 https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.18-el7-x86_64.tar.gz 2:新建一个my.cnf文 ...

  6. centos5.8安装mysql_Centos5.8上面用Shell脚本一键安装mysql5.5.25源码包

    最近在研究mysql集群,至少要安装部署2台或者多台mysql数据库,操作起来即麻烦又很耗时,今天根据安装步骤写了一个Shell脚本,只需执 行以下脚本就可以快速安装mysql数据库,对初学者或者想学 ...

  7. Shell脚本一键安装软件

    一.JDK一键安装 基本步骤: 1.上传 JDK 压缩包到虚拟机的 opt 目录下 2.启动 Shell 脚本即可一键安装 3.脚本内容 #!/bin/bash cd /opt gz=`find -n ...

  8. shell脚本一键安装LNMP(liunx+nginx+mysql+php)环境

    #!/bin/bash # author:kwin # Email:kwinwong@hotmail.comsrc="/usr/local/src/" cd $src#找到指定进程 ...

  9. 用shell脚本一键搭建LNMP环境实战

    为了配合上一篇文字,这里先给大家整理一键如何部署LNMP环境; 其实在生产环境中中小企业也是很喜欢用这样的软件包,因为毕竟源码包安装步骤那么多谁也不能一步一步的在哪敲出来,在生产线上你说一台lnmp服 ...

最新文章

  1. 树莓派IO口驱动代码的编写、微机总线地址、物理地址、虚拟地址、BCM2835芯片手册
  2. 复制带随机节点的链表
  3. 2016级算法第四次上机-B ModricWang的序列问题
  4. 英伟达赚钱能力创历史新高,老黄:GPU供不应求我也很急
  5. first network error, wait for 15 seconds
  6. JAVA实现简单的FTP服务器
  7. 机器人学导论学习笔记(持续更新)
  8. linux 在ftp gt 下登录,cutftp显示的是啥意思?
  9. vs2015安装+下载详细教程
  10. 随便写了个猪八戒网的任务小助手“小八戒”,需要的拿去
  11. Asp.net 万年历
  12. 计算机系统时间显示不准确的原因,电脑时间总是不对原因 电脑时间总是不对三种解决方案...
  13. 马尔可夫决策过程和贝尔曼方程
  14. Oracle 11g用exp无法导出空表的处理方法
  15. STM32单片机初学心得
  16. SQL14 从titles表获取按照title进行分组,注意对于重复的emp_no进行忽略。
  17. 曾经最好用的浏览器凉了?正在被大批网站抛弃
  18. 第四章 账号权限管理
  19. 约数国王(A king)
  20. 快速将PDF图片转成PPT

热门文章

  1. redis php高级使用_项目中应用Redis+Php的场景
  2. android xml反编译原理,记一次resources.arsc文件hex修改原理分析
  3. linux命令80字符,Linux终端:用cat命令查看不可见字符
  4. html优化布局什么意思,HTML标签布局对seo的重要性(如:h1,p,alt等标签)
  5. .netcore 判断是否 ajax 请求_第3部分-异步使用2-2:Ajax 之 状态码
  6. python3的配置文件类单例实现_单例模式的几种实现方式及对比
  7. k8s springboot 文件_30分钟无痛上云——springboot项目部署到kubernetes
  8. pythonweb项目源码下载_最新Python WEB开发在线教育项目之谷粒教育 软件源码齐全...
  9. 语料库与python应用_语料库与Python应用/语料库翻译学文库
  10. 搭建gradle环境