LAMP源码编译安装脚本

#!/bin/bash                     #
#auto make install LAMP         # 
#by author LingShu 2018-04-25   #
#################################

#test network
#ping -c 4 www.baidu.com  &>/dev/null
#if [ $? -ne 0 ];then
#   echo -c "\033[32mplease check network configuration...\033[0m"
#   exit
#fi

#define httpd dir path && variable
H_FILES=httpd-2.2.27.tar.gz
H_FILES_DIR=httpd-2.2.27
H_DOWNLOAD_URL=http://archive.apache.org/dist/httpd/httpd-2.2.27.tar.gz
H_PREFIX=/usr/local/apache/
H_CONF=/usr/local/apache/conf/httpd.conf
H_SERVER=/usr/local/apache/bin/apachectl


#define mysql dir path && variable
M_FILES=mysql-5.7.13.tar.gz
M_boost=boost_1_59_0.tar.gz
M_FILES_DIR=mysql-5.7.13
M_boost_dir=/document/boost_1_59_0
M_DOWNLOAD_URL=https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.13.tar.gz
M_boost_url=https://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
M_PREFIX=/usr/local/mysql/
M_DATA=/date/mydata

#define initialise mysqld parameter
M_CONF=/etc/my.cnf
M_INIT_SH=/usr/local/mysql/bin/mysqld
M_START_SH=/usr/local/mysql/support-files/mysql.server
M_INIT_FILE=/usr/local/mysql/init.txt
M_LOG_DIR=/var/log/mysql
M_PID_DIR=/var/run/mysql
M_LOG=log-error=/var/log/mysql/mysql.log
M_PID=pid-file=/var/run/mysql/mysql.pid
M_LOGIN=/usr/local/mysql/bin/mysql

#define php dir path && variable
P_FILES=php-5.3.28.tar.gz
P_FILES_DIR=php-5.3.28
P_DOWNLOAD_URL=http://mirrors.sohu.com/php/php-5.3.28.tar.gz
P_PREFIX=/usr/local/php5/
P_CONFIG_FILE=/usr/local/php5/etc/
P_APXS2=/usr/local/apache/bin/apxs
P_DB=/usr/local/mysql/
P_INDEX=/usr/local/apache/htdocs/index.php

#install compiler for LAMP
function lamp_compiler()
{
    yum install gcc gcc-c++ apr apr-util apr-devel apr-util-devel make cmake ncurses-devel openssl openssl-devel bison* libxml2 libxml2-devel
}


#install apache function
function install_apache ()
{   wget -c $H_DOWNLOAD_URL && tar -xzf $H_FILES && cd $H_FILES_DIR ; ./configure --prefix=$H_PREFIX
    if [ $? -eq 0 ];then
        make && make install
        echo -e "\033[32m the apache install successfully !\033[0m"
    else
        echo -e "\033[32m the apache install failed !!! please check...\033[0m"
        exit
    fi
$H_SERVER restart
}


#install mysql function
function install_mysql()
{
    mkdir /document
    wget -c $M_DOWNLOAD_URL;wget -c $M_boost_url && tar -zxf $M_boost -C /document && tar -zxf $M_FILES && cd $M_FILES_DIR

    cmake . -DCMAKE_PREFIX=$M_PREFIX \
-DMYSQL_DATADIR=$M_DATA \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_BOOST=$M_boost_dir \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
 
    if [ $? -eq 0 ];then
        make && make install
        echo -e "\033[32m the mysql install successfully !\033[0m"
    else
        echo -e "\033[32m the apache install failed !!! please check...\033[0m"
        exit
    fi
}

#mysql initialise configure
function init_mysql()
{

cat $M_CONF | egrep 'mariadb.log|mariadb.pid' &> /dev/null
    if [ $? -eq 0 ]
    then
            sed -i 's/mariadb/mysql/g' $M_CONF
    fi

grep "^\[mysqld_safe\]$" /etc/my.cnf
    if [ $? -ne 0 ]
    then
            sed -i "/!includedir/i [mysqld_safe]" $M_CONF
    fi

grep "^$M_LOG$" /etc/my.cnf
    if [ $? -ne 0 ]
    then
            sed -i "/mysqld_safe/a $M_LOG" $M_CONF
    fi

grep "^$M_PID$" /etc/my.cnf
    if [ $? -ne 0 ]
    then
            sed -i "/mysqld_safe/a $M_PID" $M_CONF
    fi

if [[ ! -d $M_LOG_DIR ]] && [[ ! -d $M_PID_DIR ]]
then
        mkdir $M_LOG_DIR $M_PID_DIR
fi

chown -R mysql:mysql $M_LOG_DIR $M_PID_DIR

$M_INIT_SH --initialize --user=mysql &> $M_INIT_FILE

M_PASSWD=`cat $M_INIT_FILE |grep 'root@localhost'|awk -F:\  '{print $NF}'`
$M_START_SH start
    if [ $? -eq 0 ]
    then
        echo -e  "\033[32m mysqld server start success \033[0m"
    fi
#$M_LOGIN -uroot -p$M_PASSWD

}



#install php function
function install_php()
{
    wget -c $P_DOWNLOAD_URL && tar -xzf $P_FILES && cd $P_FILES_DIR
    ./configure --prefix=$P_PREFIX --with-config-file-path=$P_CONFIG_FILE --with-apxs2=$P_APXS2 --with-mysql=$P_DB
    if [ $? -eq 0 ]
    then
        make && make install
        echo -e "\033[32m the php install successfully !\033[0m"
    else
        echo -e "\033[32m the php install failed !!! please check...\033[0m"
        exit
    fi

    if [ ! -f $H_CONF ]
    then
        echo "please check apache server "
        exit
    fi

cat $H_CONF | grep modules/libphp5.so &> /dev/null
    if [ $? -ne 0 ]
    then
        sed -i '/mpm_netware_module/i LoadModule php5_module  modules/libphp5.so' $H_CONF
        echo -e "\033[32m Module addition success \033[0m"
    else
        echo -e "\033[32m The php5 module has already existed \033[0m"
    fi

cat $H_CONF | grep index.php  &>  /dev/null
        if [ $? -ne 0 ]
        then
                sed -i 's/index.html/index.php index.html/g'  $H_CONF
        echo -e "\033[32m Home page modification success \033[0m"
    else
        echo -e "\033[32m The home page has been modified \033[0m"
        fi

cat $H_CONF | grep 'AddType application\/x-httpd-php .php'  &>  /dev/null
        if [ $? -ne 0 ]
        then
        sed -i '/mime_module/a AddType application\/x-httpd-php .php'  $H_CONF
        echo -e "\033[32m add parsing '*.php' success \033[0m"
    else
        echo -e "\033[32m Parse has been added for *.php \033[0m"
        fi

    if [ ! -f $P_INDEX ]
    then
        echo "
            <?php
                phpinfo();
            ?>
        " > $P_INDEX
        echo -e "\033[32m Test page creation success \033[0m"
    else
        echo -e "\033[32m please create test page \033[0m"
    fi
$H_SERVER restart
}


echo -e "\033[32m"

PS3=" please select ,Do you want install package of software:"
select i in install_compiler install_apache install_mysql install_php install_all exit_install
do
    case $i in
        install_compiler)
        lamp_compiler
        ;;
        install_apache)
        install_apache
        ;;
        install_mysql)
        install_mysql && init_mysql
        ;;
        install_php)
        install_php
        ;;
        install_all)
        lamp_compiler && install_apache && install_mysql && init_mysql && install_php
        ;;
        exit_install)
        echo -e "Exin in...\033[0m"
        exit
        ;;
        *)
        echo -e "\033[32m please select {1:install compiler|2:install apache|3:install mysql|4:install php |5:install all |6:exit}\033[0m"
    esac
done
 

posted @ 2018-06-08 09:57  翎戍  阅读(136)  评论(0编辑  收藏  举报