if條件綜合shell一鍵安裝LAMP

來源:互聯網
上載者:User

標籤:伺服器   local   

通過IF語句和變數來編寫營運指令碼,

一鍵安裝LAMP環境的指令碼;

一鍵源碼安裝LAMP指令碼,先分解指令碼的各個功能;


列印菜單:

1)安裝Apache WEB伺服器

2)安裝Mysql DB伺服器

3)安裝PHP伺服器

4)整合LAMP架構並啟動服務


1、Apache伺服器安裝部署。

下載httpd-2.2.27.tar.gz版本,下載URL,解壓,進入安裝目錄,configure;make;make install


2、MySQL伺服器的安裝

下載MySQL-5.5.20.tar.bz2版本,下載URL,解壓,進入安裝目錄,configure;makeinstall


3、PHP伺服器安裝

下載PHP-5.3.8.tar.bz2版本,下載URL,解壓,進入安裝目錄,configure;make;make install


4LAMP架構的整合和服務啟動

/usr/local/apache2/bin/apachectl start


vi htdocs/index.php

<?php

phppinfo();

?>

指令碼頁

#!bin/bash

#auto install LAMP

#by lirp 2015-7


#Httpd define path variable

H_FILES=httpd-2.2.27.bar.bz2

H_FILES_DIR=httpd-2.2.27

H_URL=http://mirrors.cnnic.cn/apache/httpd/

H_PREFIX=/usr/local/apache2/


#mysql define path variable

M_FILES=mysql-5.5.20.tar.gz

M_FILES_DIR=mysql-5.5.20

M_URL=http://downl.chinaunix.net/distfiles/

M_PREFIX=/usr/local/mysql/


#PHP define path variable

P_FILES=php-5.3.28.bar.bz2

P_FILES_DIR=php-5.3.28

P_URL=http://mirrors.sohu.com/php/

P_PREFIX=/usr/local/php5/


#auto install httpd

if [ -z "$1" ];then

echo -e "\033[36mplease select Install Menu follow:\033[0m"

echo -e "\033[32ml)編譯安裝Apache伺服器\033[1m"

echo "2)編譯安裝MySQL伺服器"

echo "3)編譯安裝PHP伺服器"

echo "4)配置index.php並啟動LAMP服務"

echo -e"\033[31mUsage: { /bin/sh $0 1|2|3|4|help}\033[0m"

exit

fi

if [[ "$1" -eq "1" ]];then

wget -c $H_URL/$H_FILES &&tar -jxvf $H_FILES &&cd $H_FILES_DIR ;./configure --prefix=$H_PREFIX

    if [ $? -eq 0 ];then

        make &&make install

        echo -e "\033[32mThe $H_FILES_DIR sever install successfully!\033[0m"

    else

        echo -e "\033[32mThe $H_FILES_DIR sever install failed,please check...!\033[0m"

        exit

    fi

fi



#auto install mysql

if [[ "$1" -eq "2" ]];then

    wget -c $M_URL/$H_FILES &&tar -zxvf $M_FILES &&cd $M_FILES_DIR $$yum install cmake -y ;cmke . -DCMAKE_INSTALL_PREFIX=$M_PREFIX \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DMYSQL_DATADIR=/date/mysql \

-DSYSCONFDIR=mysql \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306 \

-DWITH_XTRADB_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_PARTITIOM_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_EXTRA_CHARSETS=1 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_BIG_TABLES=1 \

-DWITH_DEBUG=0

    if [ $? -eq 0 ];then

        make &&make install

        echo -e "\033[32mThe $M_FILES_DIR sever install successfully!\033[0m"

    else

        echo -e "\033[32mThe $M_FILES_DIR sever install failed,please check...!\033[0m"

        exit

    fi

fi



#auto install php server

if [[ "$1" -eq "3" ]];then

wget -c $P_URL/$P_FILES &&tar -jxvf $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/bin/apxs

    if [ $? -eq 0 ];then

        make ZEND_EXTRA_LIBS=`-liconv` && make inatall

        echo -e "\033[32mThe $P_FILES_DIR sever install successfully!\033[0m"

    else

        echo -e "\033[32mThe $P_FILES_DIR sever install failed,please check...!\033[0m"

        exit

    fi

fi


if [[ "$1" -eq "4" ]];then

    sed -i `/DirectoryIndex/s/index.html/indwx.php index.htl/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

fi


嘿嘿完了。。。


本文出自 “撲克臉” 部落格,轉載請與作者聯絡!

if條件綜合shell一鍵安裝LAMP

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.