LAMP腳本

安裝LAMP環境腳本說明:


在安裝LAMP環境時你如果用的網上的源有時候會因爲URL地址的過期不可用導致你的腳本失效,我的做法是在本地搭建一個簡單的http,只要這個服務就好了,然後把經常需要用到軟件上傳上去,這個時候你就可以安心的跑你的腳本了。這些內容我都在CentOS6系列測試使用過可以正常使用。

#!/bin/bash
#auto install LAMP
#by tony 2016-05-22

#Httpd define path variable
#APR Install####安裝apr############################
A_FILES=apr-1.5.2.tar.gz
A_FILES_DIR=apr-1.5.2
A_URL=http://10.93.58.70/lamp/apr-1.5.2.tar.gz
A_PREFIX=/application/apr
#APR-Util Install####安裝apr –util#####################
AU_FILES=apr-util-1.5.4.tar.gz
AU_FILES_DIR=apr-util-1.5.4
AU_URL=http://10.93.58.70/lamp/apr-util-1.5.4.tar.gz
AU_PREFIX=/application/apr-util
#PCRE Install####安裝pcre###########################
PC_FILES=pcre-8.38.tar.gz
PC_FILES_DIR=pcre-8.38
PC_URL=http://10.93.58.70/lamp/pcre-8.38.tar.gz
PC_PREFIX=/application/pcre
#Apache Install####安裝apache########################
H_FILES=httpd-2.4.18.tar.gz
H_FILES_DIR=httpd-2.4.18
H_URL=http://10.93.58.70/lamp/httpd-2.4.18.tar.gz
H_PREFIX=/application/apache2/

#Mysql define path variable ####定義mysql的安裝路徑#####
M_FILES=mysql-5.5.32.tar.gz
M_FILES_DIR=mysql-5.5.32
M_URL=http://10.93.58.70/lamp/mysql-5.5.32.tar.gz
M_PREFIX=/application/mysql/

#PHP define path variable######定義php的安裝路徑#########
P_FILES=php-5.6.20.tar.gz
P_FILES_DIR=php-5.6.20
P_URL=http://10.93.58.70/lamp/php-5.6.20.tar.gz
P_PREFIX=/application/php5/

echo -e "\033[34m-------------------------\033[0m"
echo -e "\033[35mReady to set up LAMP source environment\n
Wait for 5 seconds, please select menu\033[0m"
sleep 5
if [ -z "$1" ];then
         echo -e "\033[36mPlease Select install menu follow:\033[0m"
         echo -e "\033[32m 1)編譯安裝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 "help" ]];then
        echo -e "\033[36mPlease Select Install Menu follow:\033[0m"
        echo -e "\033[32m1)編譯安裝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

##################################
#Install httpd web server 安裝httpd服務####
if [[ "$1" -eq "1" ]];then
         yum -y install gcc gcc-c++
         wget -c $A_URL  && tar zxvf $A_FILES && cd $A_FILES_DIR && ./configure --prefix=$A_PREFIX
         if [ $? -eq 0 ];then   
                 make && make install
                   echo -e "\033[32m The $A_FILES_DIR install OK!\033[0m"
         else
                   echo -e "\033[32m the $A_FILES_DIR install error,please check...\033[0m"
                   exit 0
         fi

         wget -c $AU_URL && tar zxvf $AU_FILES && cd $AU_FILES_DIR && ./configure --prefix=$AU_PREFIX --with-apr=$A_PREFIX
                   if [ $? -eq 0 ];then   
                           make && make install
                            echo -e "\033[32m The $AU_FILES_DIR install OK!\033[0m"
                   else
                            echo -e "\033[32m the $AU_FILES_DIR install error,please check...\033[0m"
                            exit 0
                   fi

         wget -c $PC_URL && tar zxvf $PC_FILES && cd $PC_FILES_DIR && ./configure --prefix=$PC_PREFIX
                            if [ $? -eq 0 ];then   
                                    make && make install
                                     echo -e "\033[32m The $PC_FILES_DIR install OK!\033[0m"
                            else
                                     echo -e "\033[32m the $PC_FILES_DIR install error,please check...\033[0m"
                                     exit 0
                            fi

wget -c $H_URL && tar -zxvf $H_FILES && cd $H_FILES_DIR && ./configure --prefix=$H_PREFIX  \
                                                                     --with-apr=$A_PREFIX \
                                                                     --with-apr-util=$AU_PREFIX \
                                                                     --with-pcre=$PC_PREFIX \
                                                                     --enable-so \
                                                                     --enable-rewrite
                                             if [ $? -eq 0 ];then
                                               make && make install
                                               cp $H_PREFIX/bin/apachectl /etc/init.d/httpd
                                           echo "# chkconfig: 2345 50 90" >> /etc/init.d/httpd && chkconfig \
                                          --add httpd && chkconfig --level 35 httpd on && /etc/init.d/httpd restart
                                           echo -e "\033[32m----------------------------------\033[0m"
                                            echo -e "\033[32m The $H_FILES_DIR Server install Success ! \033[0m"
                                     else
         echo -e "\033[32m The $H_FILES_DIR Make or Make install ERROP,please check....\033[0m"
                                               exit 0
                   fi
fi

#Install mysql DB server安裝mysql服務####
if [[ "$1" -eq "2" ]];then
         yum -y install make cmake gcc-c++ bison ncurses ncurses-devel libaio-devel
         groupadd mysql
         useradd mysql -s/sbin/nologin -M -g mysql
         wget -c $M_URL && tar -zxvf $M_FILES && cd $M_FILES_DIR &&  cmake ./ \
-DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
if [ $? -eq 0 ];then
    make && make install 
    ln -s /application/mysql-5.5.32 /application/mysql
    cp support-files/mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    chown mysql.mysql /application/mysql
    chown mysql.mysql /data
    echo 'export PATH=/application/mysql/bin:$PATH '>>/etc/profile
    source /etc/profile
        mv /etc/my.cnf /etc/my.cnf.bak
    cat >/etc/my.cnf <<EOF
[mysqld]
port= 3306
socket= /application/mysql-5.5.32/tmp/mysql.sock
datadir=/data/mysql
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=mysql-bin
server-id = 1
auto_increment_offset=1
auto_increment_increment=2
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
replicate-do-db =all
EOF
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/mysql --user=mysql
/etc/init.d/mysqld start
chkconfig mysqld on
mysqladmin -uroot password 'hwg123'
                   echo -e "\n\033[32m-----------------------------------------------\033[0m"
                echo -e "\033[32mThe $M_FILES_DIR Server Install Success !\033[0m"
        else
                echo -e "\033[32mThe $M_FILES_DIR Make or Make install ERROR,Please Check......"
                exit 0
        fi
fi

#Install PHP server安裝php服務####
if [[ "$1" -eq "3" ]];then
         yum install libxml2-devel -y
wget -c $P_URL  &&  tar -zxvf $P_FILES && cd $P_FILES_DIR &&./configure --prefix=$P_PREFIX  \
                                         --with-config-file-path=/usr/local/php/etc  \
                                         --with-apxs2=$H_PREFIX/bin/apxs \
                                         --with-mysql=$M_PREFIX 
        if [ $? -eq 0 ];then
                make && make install
                echo -e "\n\033[32m-----------------------------------------------\033[0m"
                echo -e "\033[32mThe $P_FILES_DIR Server Install Success !\033[0m"
        else
                echo -e "\033[32mThe $P_FILES_DIR Make or Make install ERROR,Please Check......"
                exit 0
        fi
fi
####################################
if [[ "$1" -eq "4" ]];then

         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 eth0|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

注意:
1,腳本在centos6.5-6.9之間跑的最順利,腳本的IP和路徑需要更改一下。
2,我把常用軟件鏈接如下: 鏈接:https://pan.baidu.com/s/1xGBaMO_JKx_sy8al1bW5SQ 密碼: 1cqw
3,腳本運行完成啓動mysql可能會提示找不到這個命令,需要 source /etc/profile一下。
4,如果數據庫換成5.6的版本需要把這個參數改變- DWITHOUT_PARTITION_STORAGE_ENGINE=0 \
5,如果你不是root權限運行腳本請先給腳本chmod +x lamp_install.sh

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