码迷,mamicode.com
首页 > 其他好文 > 详细

我的第一次--LAMP安装脚本

时间:2015-08-01 06:38:00      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:lamp

#!/bin/bash
#20150730 by wyw 
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install lnmp"
    exit 1
fi

# set clour
Color_Text()
{
    echo -e " \033[0;$2m$1\033[0m"
}

Echo_Red()
{
    echo $(Color_Text "$1" "31")
}

Echo_Green()
{
    echo $(Color_Text "$1" "32")
}

Echo_Yellow()
{
    echo $(Color_Text "$1" "33")
}

Echo_Blue()
{
    echo $(Color_Text "$1" "34")
}

cur_dir=$(pwd)

Echo_Yellow "+------------------------------------------------------------------------+"
Echo_Red "    (1)  INSTALL APACHE2.4                  "
Echo_Yellow "+------------------------------------------------------------------------+"
Echo_Blue "   (2)  INSTALL MYSQL5.5                 "
Echo_Yellow "+------------------------------------------------------------------------+"
Echo_Green "  (3)  INSTALL PHP5.4                                                   "
Echo_Yellow "+------------------------------------------------------------------------+"
echo " (4)  INSTALL LAMP"
Echo_Yellow "+------------------------------------------------------------------------+"
read -t 30 -p "please Enter your choice (1, 2, 3,or 4): "  cho

 CentOS_Dependent()
{
    Echo_Green "[+] yum install packets..."
    yum -y install epel-release 
    for packages in gcc gcc-c++ gcc-g77 cmake flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libmcrypt-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel mysql-devel net-snmp-devel curl-devel perl-DBI;
    do yum -y install $packages; done
}
 Install_Apache_24()
{   
    Echo_Green "[+] Installing apache,please wait..."
    yum install gcc gcc-c++ gcc-g77
    tar xf ${cur_dir}/httpd-2.4.12.tar.gz
    tar xf ${cur_dir}/apr-1.5.1.tar.gz
    tar xf ${cur_dir}/apr-util-1.5.4.tar.gz
    cd ${cur_dir}/apr-1.5.1
    ./configure --prefix=/usr/local/apr &>/dev/null
    make &>/dev/null && make install &>/dev/null
    cd ${cur_dir}/apr-util-1.5.4
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &>/dev/null
    make &>/dev/null && make install &>/dev/null
    cd ${cur_dir}/httpd-2.4.12
    ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=prefork &>/dev/null
if [ "$?" -eq "0" ];then
    make &>/dev/null && make install &>/dev/null
    Echo_Blue "apache install....................OK!"
    else echo "apache install....................fail!"
fi
    echo "PidFile  "/var/run/httpd.pid"" >> /etc/httpd/httpd.conf
    \cp ${cur_dir}/conf/httpd /etc/init.d/httpd
    chmod +x /etc/init.d/httpd
    chkconfig --add httpd
    chkconfig --level 35 httpd on
    /usr/local/apache/bin/apachectl &>/dev/null
    netstat -luntp|grep 80
    STAT=`netstat -luntp|grep 80|cut -d: -f4`
if [ "$STAT" -eq "80" ];then
    Echo_Green "apache start ....................OK!" 
    else echo "apache start ....................Fail!"
fi
}

Install_Mysql_55 ()
{
    Echo_Blue "[+] 开始安装mysql,请等待..."
    yum -y remove mysql
    yum -y install gcc gcc-c++ ncurses-devel perl cmake &>/dev/null
    tar xf ${cur_dir}/mysql-5.5.42.tar.gz
    cd ${cur_dir}/mysql-5.5.42
    cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/opt/mydata/data -DSYSCONFDIR=/opt/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
    make -j2 && make install -j2
if [ "$?" -eq "0" ];then
    Echo_Blue "mysql install....................OK!"
    else Echo_Red  "mysql install....................Fail!"
fi
    groupadd -r mysql
    useradd -g mysql -r -d /opt/mydata/data/ mysql
    mkdir -p /opt/mydata/data 
    chown -R mysql:mysql /opt/mysql
    \cp support-files/mysql.server /etc/rc.d/init.d/mysqld
    \cp ${cur_dir}/conf/my.cnf /opt/mysql/my.cnf -rf
    chmod +x /etc/rc.d/init.d/mysqld
    cd /opt/mysql
    ./scripts/mysql_install_db --user=mysql --datadir=/opt/mydata/data/
    /etc/rc.d/init.d/mysqld start
    netstat -luntp|grep 3306
    STAT=`netstat -luntp|grep 3306 |wc -l`
if [ "$STAT" -eq "1" ];then
    Echo_Green "mysql start....................OK!" 
    else echo "mysql start....................Fail!"
fi
    echo "export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin:/opt/mysql/bin/" > /etc/profile.d/mysql.sh
    chmod 755 /etc/profile.d/mysql.sh
    source /etc/profile.d/mysql.sh
}

Install_PHP_54()
{
    Echo_Green "[+] Installing php5.4 ..."
    tar xf ${cur_dir}/php-5.4.41.tar.gz && cd php-5.4.41
    ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/opt/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 &>> /dev/null

    make && make install
if [ "$?" -eq "0" ];then
    Echo_Green "php install....................OK!"
    else Echo_Red  "php install....................Fail!"
fi
    \cp php.ini-production /usr/local/php/etc/php.ini
    \cp /etc/httpd/httpd.conf /etc/httpd/httpd.confbak
    sed -i ‘/DirectoryIndex/s/index.html/index.php index.html/g‘ /etc/httpd/httpd.conf
    sed -i ‘s/#ServerName www.example.com:80/ServerName www.example.com:80/g‘ /etc/httpd/httpd.conf
    echo "AddType application/x-httpd-php .php" >> /etc/httpd/httpd.conf
    \cp ${cur_dir}/conf/p.php /usr/local/apache/htdocs/
    service httpd restart
    IP=`ifconfig eth0|grep "Bcast"|awk ‘{print $2}‘|cut -d: -f2`
    Echo_Green "You can access http://$IP/p.php"

}

case "${cho}" in
    1)
    Install_Apache_24    
    ;;
    2)
    Install_Mysql_55    
    ;;
    3)
    CentOS_Dependent
    Install_PHP_54        
    ;;
    4)
    Echo_Green "[+] lamp install..."
        Install_Apache_24 && cd ${cur_dir} && Install_Mysql_55 && cd ${cur_dir} && Install_PHP_54
    ;;
    *)
        Echo_Red "Usage: $cho {please Enter your choice (1, 2, 3,or 4)}"
        ;;
esac


我的第一次--LAMP安装脚本

标签:lamp

原文地址:http://024mj.blog.51cto.com/10252785/1680693

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!