case語句安裝LAMP大概思路

#!/bin/sh
#auto install LAMP shell
#by zkg 2019-06-26

#定義apache變量
H_FILES=httpd-2.4.39.tar.gz
H_FILES_DIR=httpd-2.4.39
H_URL=http://mirrors.cnnic.cn/apache/httpd/
H_PREFIX=/usr/local/apache2

#定義MYSQL DB變量
M_FILES=mysql-5.5.33.tar.gz
M_FILES_DIR=mysql-5.5.33
M_URL=https://downloads.mysql.com/archives/community/?tpl=files&os=src&version=5.5.33/
M_PREFIX=/usr/local/mysql55

#定義PHP變量
P_FILES=php-7.0.9.tar.gz
P_FILES_DIR=php-7.0.9
P_URL=http://php.net/get/php-7.0.9.tar.gz/from/a/mirror
P_PREFIX=/usr/local/php7

#一鍵安裝菜單
echo -e "\033[32m1)安裝Apache WEB服務器\033[1m"
echo "2)安裝Mysql DB服務器"
echo "3)安裝PHP服務器"
echo "4)整合LAMP架構並啓動服務"
echo "Please select Install Menu(1-4):"
read MENU
if [ "$MENU" -ne 1 -o "$MENU" -ne 2 -o "$MENU" -ne 3 -o "$MENU" -ne 4 ];then
echo -e "\033[32mNot input 大於4或小於1的數字,Please select Install Menu(1-4):\033[0m"
fi

#安裝apache WEB服務器
case $MENU in
1)
wget -c $H_URL/$H_FILES && tar -xzvf $H_FILES && cd $H_FILES_DIR && ./configure --prefix=$H_PREFIX
if [ $? -eq 0 ];then
make && make install
echo -e "\033[32mthe $H_FILES_DIR Server Install successfully!\033[0m"
else
echo -e "\033[32mthe $H_FILES_DIR Server Install Failed,please check...!\033[0m"
exit 0
fi
;;

#安裝Mysql DB服務器
2)
wget -c $M_URL/$M_FILES && tar -xzvf $M_FILES && cd $M_FILES_DIR && yum -y install cmake;cmake . -DCMAKE_INSTALL_PREFIX=$M_PREFIX \
-DMYSQL_DATADIR=/data/myql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/data/mysql.sock \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0

    cp support-files/my*.cnf /etc/my.cnf
    cp support-files/mysql.server /etc/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on

    if [ $? -eq 0 ];then
            make && make install
            echo -e "\033[32mthe $M_FILES_DIR Server Install successfully!\033[0m"
    else
            echo -e "\033[32mthe $M_FILES_DIR Make or Make install ERROR,please check...!\033[0m"
            exit 0
    fi
    ;;

#安裝PHP服務器
3)
wget -c $P_URL/$P_FILES && tar -xzvf $P_FILES && cd $P_FILES_DIR && ./configure --prefix=$P_PREFIX \
--with-config-file-path=$P_PREFIX/etc \
--with-mysql=$M_PREFIX \
--with-apxs2=$H_PREFIX/apxs

    if [ $? -eq 0 ];then
            make ZEND_EXTRA_LIBS='-liconv' && make install
            echo -e "\033[32mthe $P_FILES_DIR Server Install successfully!\033[0m"
    else
            echo -e "\033[32mthe $P_FILES_DIR Server Install Failed,please check...!\033[0m"
            exit 0
    fi
    ;;

#整合LAMP架構並啓動服務
4)
sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' $H_PREFIX/conf/httpd.conf
$H_PREFIX/bin/apachectl restart
echo " AddType application/x-httpd-php .php" >>$H_PREFIX/conf/httpd.conf
IP=ifconfig eth1|grep "Bcast"|awk '{print $2}'|cut -d: -f2
echo "you can access http://$IP/"

cat >$H_PREFIX/htdocs/index.php <<EOF
<?php
phpinfo()
?>
EOF
;;
esac
case語句安裝LAMP

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章