lamp安装脚本(编译方式)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamp安装脚本(编译方式)相关的知识,希望对你有一定的参考价值。

#!/bin/bash

#

# **********************************************************

# * filename:    lamp_install.sh   *

# * discription:    lamp install   *

# * version:    centos6.7 apr-1.5.2 apr-util-1.5.4     *

# *    httpd-2.4.6 mysql-5.5.32  php-5.6.15   *

# * date:    2016/09/07                     *

# * author:         wangbo                                 *

# * mail:    [email protected]                       *

# **********************************************************

#



function init()

{

    #shutdown SELINUX

    setenforce 0;

    #stop iptables

    /etc/init.d/iptables stop;


    echo "***********************************";

    echo "*init finished!                   *";

    echo "***********************************";

}


#check root user ,net

function base_check()

{

    #check user root

    if [ `whoami` = "root" ]

    then

echo "***********************************";

echo "*root user                        *";

echo "***********************************";

    else

echo "***************************************";

echo "*change to root,please input password *";

echo "***************************************";

su - root -s /bin/bash /usr/local/src/lamp_install.sh;

#exit 1;

    fi

    echo "***********************************";

    echo "*is root user!                    *";

    echo "***********************************";

    #the count of lose package

    lpcount = ping -c 4 www.baidu.com | grep received | awk ‘{print $6}‘ | sed -e ‘s/%//g‘;

    #check net

    if [ $lpcount -gt 2 ]

    then

echo "***********************************";

echo "*Please check your network        *";

echo "***********************************";

exit 1;

    fi


    echo "***********************************";

    echo "*network is ok!                   *";

    echo "***********************************";

}


function package_check()

{

    echo "###";

}


function apr_install()

{

    cd /usr/local/src;

    tar xzf apr-1.5.2.tar.gz;

    cd apr-1.5.2;

    ./configure \

    --prefix=/usr/local/apr

    if [ $? -ne 0 ]

    then

echo "***********************************";

echo "*apr configure failed,stop...     *";

echo "***********************************";

exit 1;

    fi

    make && make install;

    if [ $? -ne 0 ]

    then        

echo "***********************************";

echo "*php make failed , stop...        *";

echo "***********************************";

    fi

    exit 1;

    echo "***********************************";

    echo "*apr installed successfully!      *";

    echo "***********************************";

}


function apr_util_install()

{

    cd /usr/local/src;

    tar xzf apr-util-1.5.4.tar.gz;

    cd apr-util-1.5.4;

    ./configure \

    --with-apr=/usr/local/apr \

    --prefix=/usr/local/apr-util

    if [ $? -ne 0 ]

    then

echo "***********************************";

echo "*apr-util configure failed,stop...*";

echo "***********************************";

exit 1;

    fi

    make && make install;

    if [ $? -ne 0 ]

    then        

echo "***********************************";

echo "*apr-util make failed , stop...   *";

echo "***********************************";

    fi

    exit 1;


    echo "***********************************";

    echo "*apr-util installed successfully! *";

    echo "***********************************";

}


function httpd_install()

{

    yum -y install pcre pcre-devel openssl openssl-devel zlib-devel;

    cd /usr/local/src/;

    tar xzf httpd-2.4.16.tar.gz;

    cd httpd-2.4.16;

    ./configure \

    --prefix=/usr/local/apache \

    --sysconfdir=/etc/httpd \

    --enable-so \

    --enable-rewrite \

    --enable-ssl \

    --enable-cgi \

    --enable-cgid \

    --enable-modules=most \

    --enable-mods-shared=most \

    --enable-mpms-shared=all \

    --with-apr=/usr/local/apr \

    --with-apr-util=/usr/local/apr-util

    if [ $? -ne 0 ]

    then

echo "********************************"

echo "*httpd configure failed,stop...*";

echo "********************************"

exit 1;

    fi

    make && make install;

    if [ $? -ne 0 ]

    then 

echo "***************************";

echo "*php make failed , stop...*";

echo "***************************";

exit 1;

    fi


    if [$? -ne 0 ]

    then

echo "**************************"

echo "*httpd make filed,stop...*";

echo "**************************"

exit 1;

    fi

    sed -i ‘/^ServerRoot/a PidFile "/var/run/httpd.pid"‘ /etc/httpd/httpd.conf;

    cp /usr/local/src/httpd /etc/init.d/httpd;

    chmod +x /etc/init.d/httpd;

    export PATH=$PATH:/usr/local/apache/bin;

    chkconfig --add httpd;

    chkconfig --level 35 httpd on;

    echo "*******************************"

    echo "*httpd installed successfully!*";

    echo "*******************************"

}


function mysql_install()

{

    cd /usr/local/src;

    tar xzf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/;

    cd /usr/local;

    ln -sv mysql-5.5.32-linux2.6-x86_64 mysql;

    groupadd -r -g 306 mysql;

    useradd -g 306 -r -u 306 mysql;

    if [ $? -ne 0 ]

    then

echo "************************************";

echo "*create user or group faild,stop...*";

echo "************************************";

exit 1;

    fi

    cd /usr/local/mysql;

    chown -R mysql.mysql .;

    chown -R mysql data;

    chmod o-rx data;

    scripts/mysql_install_db --user=mysql;

    chown -R root /usr/local/mysql/*

    chown -R mysql.mysql /usr/local/mysql/data

    cp support-files/mysql.server /etc/init.d/mysqld;

    cp support-files/my-large.cnf /etc/my.cnf;

    export PATH=$PATH:/usr/local/mysql/bin;

    sed -i ‘$a MANPATH /usr/local/mysql/man‘ /etc/man.config;

    touch /etc/ld.so.conf.d/mysql.conf;

    sed -i ‘$a /usr/local/mysql/lib‘ /etc/ld.so.conf.d/mysql.conf;

    ln -sv /usr/local/mysql/include /usr/include/mysql;

    echo "*******************************";

    echo "*mysql installed successfully!*";

    echo "*******************************";

}



function php_install()

{

    yum -y install libxml2 libxml2-devel bzip2 bzip2-devel;

    if [ $? -ne 0 ]

    then

echo "********************************************";

echo "*dependency package installed faild,stop...*";

echo "********************************************";

exit 1;

    fi

    rpm -ivh libmcrypt-2.5.8-4.el5.centos.x86_64.rpm libmcrypt-devel-2.5.8-4.el5.centos.x86_64.rpm

    if [ $? -ne 0 ]

    then

echo "********************************************"

echo "*dependency package installed faild,stop...*";

echo "********************************************"

exit 1;

    fi

    cd /usr/local/src;

    tar xf php-5.6.15.tar.bz2;

    cd php-5.6.15;

    ./configure \

    --prefix=/usr/local/php \

    --with-mysql=/usr/local/mysql \

    --with-openssl \

    --with-mysqli=/usr/local/mysql/bin/mysql_config \

    --enable-mbstring \

    --with-freetype-dir  \

    --with-jpeg-dir \

    --with-png-dir \

    --with-zlib \

    --with-libxml-dir=/usr \

    --enable-xml \

    --enable-sockets \

    --with-apxs2=/usr/local/apache/bin/apxs \

    --with-mcrypt \

    --with-config-file-path=/etc \

    --with-config-file-scan-dir=/etc/php.d \

    --with-bz2 \

    --enable-maintainer-zts

    if [ $? -ne 0 ]

    then

echo "******************************";

echo "*php configure failed,stop...*";

echo "******************************";

exit 1;

    fi

    make && make install;

    if [ $? -ne 0 ]

    then

echo "****************************";

echo "*php make failed , stop... *";

echo "****************************";

    exit 1;

    fi

    cp php.ini-production /etc/php.ini;

    sed -i ‘392a AddType application/x-httpd-php .php‘ /etc/httpd/httpd.conf;    

    sed -i ‘393a AddType application/x-httpd-php-source .phps‘ /etc/httpd/httpd.conf;    

    sed -i ‘s/index.html$/& index.php/‘ /etc/httpd/httpd.conf;

    echo "*****************************";

    echo "*php installed successfully!*";

    echo "*****************************";

}


function show_main_menu()

{

    echo "********************************";   

    echo "* the program of lamp install  *";

    echo "********************************";

    echo "*    1、一键安装               *";

    echo "********************************";

    echo "*    2、逐个安装               *";

    echo "********************************";

    

}


function show_second_menu()

{

    #请按照apr->apr-util->http->mysql->php顺序安装

    echo "*******************************";  

    echo "* please choose the program   *";

    echo "*******************************";  

    echo "*    1、初始化                *";

    echo "*******************************";  

    echo "*    2、基础检查              *";

    echo "*******************************";  

    echo "*    3、安装包检查            *";

    echo "*******************************";  

    echo "*    4、安装 apr              *";

    echo "*******************************";  

    echo "*    5、安装 apr-util         *";

    echo "*******************************";  

    echo "*    6、安装 httpd            *";

    echo "*******************************";  

    echo "*    7、安装mysql             *";

    echo "*******************************";  

    echo "*    8、安装php               *";

    echo "*******************************";  

}


function all_install()

{

    apr_install;

    apr_util_install;

    httpd_install;

    mysql_install;

    php_install;

}


function tmp()

{

    show_second_menu;

    choose_install;

}


function choose_install()

{

    echo -e ">>\c";   

    read num;

    if [ $num -eq "1" ]

    then

init;

tmp;

    elif [ $num -eq "2" ]

    then

base_check;

tmp;

    elif [ $num -eq "3" ]

    then

package_check;

tmp;

    elif [ $num -eq "4" ]

    then

apr_install;

tmp;

    elif [ $num -eq "5" ]

    then

apr_util_install;

tmp;

    elif [ $num -eq "6" ]

    then

httpd_install;

tmp;

    elif [ $num -eq "7" ]

    then

mysql_install;

tmp;

    elif [ $num -eq "8" ]

    then

php_install;

tmp;

    fi

}



function lamp_install()

{

    show_main_menu;

    echo -e ">>\c";

    read  num 2&>1 > /dev/null;

    if [ $num -eq "1" ]

    then

all_install;

    elif [ $num -eq "2" ]

    then

tmp;

    fi

}


lamp_install;


本文出自 “shell实现计算器” 博客,请务必保留此出处http://codekong.blog.51cto.com/10704076/1850915

以上是关于lamp安装脚本(编译方式)的主要内容,如果未能解决你的问题,请参考以下文章

shell脚本编译安装LAMP环境

编译安装LAMP脚本

一键编译安装lamp

shell自动化安装LAMP

lanmp的一键安装脚本

LAMP 之 自动化编译安装