LAMP一键安装脚本

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:
#!/bin/bash
path="/server/packages"
file_path="/server/packages/LAMP-php7"
php_file_path="/usr/local/php"
apache_file_path="/usr/local/apache2"
mysql_user=mysql
mysql_package=mysql-5.5.48
mysql_path=/usr/local/mysql
init(){
   if [ ! -d $path ];then
       mkdir -p $path
   fi
   yum -y install lsof net-tools gcc* openssl zlib-devel libpng-devel gcc gcc-c++ make unzip libxml2-devel python-devel libtool* openssl-devel ncurses-devel cmake bison  &>/dev/null
   if [ $? -ne 0 ];then
       echo "Install depend failed."
       exit
   fi
   if [ ! -e $path/LAMP-php7.zip ];then
       wget -P ${path}/ http://172.16.0.7/packages/LAMP-php7.zip &>/dev/null
       if [ $? -ne 0 ];then
           echo "download error."
           exit 1
       else
           echo "download success."
       fi
   fi
   unzip $path/LAMP-php7.zip -d /server/packages/ &>/dev/null
       if [ $? -eq 0 ];then
           cd $path/LAMP-php7
           /bin/ls *.tar.gz > ls.list
           for TAR in `cat ls.list`
           do
               /bin/tar -xf $TAR
           done
           [ $? -eq 0 ]&&{
               echo "uzip success."
           }
       else
           echo "unzip error."
           exit 1
   fi
}
install_apache(){
    echo "install libxml2..."
    cd $file_path/libxml2-2.9.1
    ./configure --prefix=/usr/local/libxml2/ &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "libxml2 install failed."
            exit 2
        }
    else
        echo "libxml2 configure failed."
        exit 2
    fi
    echo "install libmcrypt..."
    cd $file_path/libmcrypt-2.5.8
    ./configure --prefix=/usr/local/libmcrypt &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "libmcrypt install failed."
            exit 2
        }
    else
        echo "libmcrypt configure failed."
        exit 2
    fi   
    echo "install libltdl..." 
    cd $file_path/libmcrypt-2.5.8/libltdl
    ./configure --enable-ltdl-install &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "libltdl install failed."
            exit 2
        }
    else
        echo "libltdl configure failed."
        exit 2
    fi
    echo "install mhash..."
    cd $file_path/mhash-0.9.9.9
    ./configure &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "mhash install failed."
            exit 2
        }
    else
        echo "mhash configure failed."
        exit 2
    fi
    echo "install mcrypt..."
    cd $file_path/mcrypt-2.6.8
    export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib/:/usr/local/lib
    ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "mcrypt install failed."
            exit 2
        }
    else
        echo "mcrypt configure failed."
        exit 2
    fi
    echo "install zlib..."
    cd $file_path/zlib-1.2.3
    ./configure &>/dev/null
    sed -i "s#\-O3 -DUSE_MMAP#\-O3 -DUSE_MMAP -fPIC#g" Makefile
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "zlib install failed."
            exit 2
        }
    else
        echo "zlib configure failed."
        exit 2
    fi
    echo "install libpng..."
    cd $file_path/libpng-1.2.31
    ./configure --prefix=/usr/local/libpng &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "libpng install failed."
            exit 2
        }
    else
        echo "libpng configure failed."
        exit 2
    fi
    echo "install jpeg6..."
    mkdir /usr/local/jpeg6
    mkdir /usr/local/jpeg6/bin
    mkdir /usr/local/jpeg6/lib
    mkdir /usr/local/jpeg6/include
    mkdir -p /usr/local/jpeg6/man/man1
    cd $file_path/jpeg-6b
    \cp -a /usr/share/libtool/config/config.sub ./
    \cp -a /usr/share/libtool/config/config.guess ./
    ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static &>/dev/null
        if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "jpeg6 install failed."
            exit 2
        }
    else
        echo "jpeg6 configure failed."
        exit 2
    fi
    echo "install freetype..."
    cd $file_path/freetype-2.3.5
    ./configure --prefix=/usr/local/freetype &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "freetype install failed."
            exit 2
        }
    else
        echo "freetype configure failed."
        exit 2
    fi
    echo "install apache..."
    \cp -a $file_path/apr-1.4.6 $file_path/httpd-2.4.7/srclib/apr
    \cp -a $file_path/apr-util-1.4.1  $file_path/httpd-2.4.7/srclib/apr-util
    cd $file_path/pcre-8.34
    ./configure &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "pcre install failed."
            exit 2
        }
    else
        echo "pcre configure failed."
        exit 2
    fi
    cd $file_path/httpd-2.4.7
    ./configure --prefix=/usr/local/apache2 \
    --sysconfdir=/usr/local/apache2/etc --with-included-apr \
    --enable-so --enable-deflate=shared --enable-expires=shared \
    --enable-rewrite=shared --enable-ssl &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "apache install failed."
            exit 2
        }
    else
        echo "apache configure failed."
        exit 2
    fi
    wget -O ${apache_file_path}/etc/httpd.conf http://172.16.0.7/profile/httpd.conf &>/dev/null
    if [ $? -eq 0 ];then
        /usr/local/apache2/bin/apachectl start
        id=`/usr/sbin/lsof -i :80|wc -l`
        if [ $id -gt 0 ];then
            echo -e "\033[32mhttp start success\033[0m"
        else
            echo "start failed,please check it."
        fi
     else
         echo "download config file fafield."
         exit 1
    fi
    echo "install ncurses..."
    cd $file_path/ncurses-5.9
    ./configure --with-shared --without-debug --without-ada --enable-overwrite &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "ncurses install failed."
            exit 2
        }
    else
        echo "ncurses configure failed."
        exit 2
    fi
}
#mysql_user=mysql
#mysql_path=/usr/local/mysql
init_mysql(){
    id ${mysql_user} &>/dev/null
    [ $? -ne 0 ]&&{
        useradd -r -s /sbin/nologin ${mysql_user} &>/dev/null
        if [ $? -eq 0 ];then
            echo "${mysql_user} create success."
        else
            echo "${mysql_user} create failed,please check it!"
            exit 1
        fi
    }
}
install_mysql(){
    echo "Installing..."
    cd ${file_path}/${mysql_package}/
    cmake -DCMAKE_INSTALL_PREFIX=${mysql_path} \
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all \
    -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 \
    -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=${mysql_user} \
    -DMYSQL_TCP_PORT=3306 &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -ne 0 ]&&{
           echo -e "\033[31minstall failed,please check.\033[0m"
           exit 1
        }||{
           echo "install success."
           ln -s ${mysql_path}/bin/* /usr/local/bin/ &>/dev/null
           }
    fi
    cd ${mysql_path}/
    chown -R root .
    chown -R mysql data/
    echo "configure mysql..."
    \cp ${file_path}/${mysql_package}/support-files/my-medium.cnf /etc/my.cnf &>/dev/null
    cd ${mysql_path}
    ./scripts/mysql_install_db --user=mysql &>/dev/null
    if [ $? -eq 0 ];then
        \cp ${mysql_path}/support-files/mysql.server /etc/init.d/mysqld &>/dev/null
        chmod +x /etc/init.d/mysqld
        chkconfig --add mysqld &>/dev/null
        chkconfig mysqld on &>/dev/null
        service mysqld start
        mysqladmin -uroot password 123456
        [ $? -eq 0 ]&&{
        echo "mysql configure success."
        }||{
        echo -e "\033[31mconfigure falied,please check it.\033[0m"
           }
    fi
}
install_php(){
    echo "install php..."
    cd ${file_path}/php-7.0.7
    ./configure --prefix=/usr/local/php/ \
    --with-config-file-path=/usr/local/php/etc/ \
    --with-apxs2=/usr/local/apache2/bin/apxs \
    --with-libxml-dir=/usr/local/libxml2/ \
    --with-jpeg-dir=/usr/local/jpeg6/ \
    --with-png-dir=/usr/local/libpng/ \
    --with-freetype-dir=/usr/local/freetype/ \
    --with-mcrypt=/usr/local/libmcrypt/ \
    --with-mysqli=/usr/local/mysql/bin/mysql_config \
    --enable-mbstring=all --enable-sockets \
    --with-pdo-mysql=/usr/local/mysql --with-gd \
    --without-pear &>/dev/null
    if [ $? -eq 0 ];then
        make &>/dev/null
        make install &>/dev/null
        [ $? -eq 0 ]||{
            echo "php install failed."
            exit 2
        }
    else
        echo "php configure failed."
        exit 2
    fi
    echo "php config..."
    mkdir /usr/local/php/etc
    \cp $file_path/php-7.0.7/php.ini-production /usr/local/php/etc/php.ini
    /usr/local/apache2/bin/apachectl -t
    if [ $? -eq 0 ];then
        /usr/local/apache2/bin/apachectl restart
        echo "php install & config success."
    else
        echo "php config fialed,please check it."
        exit 2
    fi
}
mon(){
    wget -O /usr/local/apache2/mon-httpd.sh http://172.16.0.7/scripts/mon-httpd.sh &>/dev/null
    echo "*/5 * * * * /bin/sh /usr/local/apache2/mon-httpd.sh" >>/var/spool/cron/root
    echo "/bin/sh /usr/local/apache2/mon-httpd.sh" >>/etc/rc.local   
}
main(){
    init
    install_apache
    init_mysql
    install_mysql
    install_php
    mon
}
main
相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
弹性计算 关系型数据库 MySQL
一键安装LAMP环境
资源编排服务ROS(Resource Orchestration Service)支持通过创建资源栈的方式一键安装LAMP环境。
|
关系型数据库 Shell 应用服务中间件
|
关系型数据库 MySQL Linux
|
关系型数据库 MySQL 应用服务中间件
|
关系型数据库 MySQL PHP
|
关系型数据库 MySQL Shell
|
关系型数据库 MySQL 应用服务中间件
|
监控 Apache 数据安全/隐私保护
|
Web App开发 监控 关系型数据库

热门文章

最新文章