564543 发表于 2016-7-22 10:42:44

LAMP动态网站搭建脚本

#!/bin/bash
#auto make install LAMP
#by authors zhang 2016

#httpd define path variable
H_FILES=httpd-2.2.17.tar.gz
H_FILES_DIR=httpd-2.2.17
H_PREFIX=/usr/local/httpd/

#mysql define path variable
M_FILES=mysql-5.5.22.tar.gz
M_FILES_DIR=mysql-5.5.22
M_PREFIX=/usr/local/mysql/


#php define path variable

P_FILES1=libmcrypt-2.5.8.tar.gz
P_FILES_DIR1=libmcrypt-2.5.8
P_PREFIX1=/usr/local/lib/

P_FILES2=mhash-0.9.9.9.tar.gz
P_FILES_DIR2=mhash-0.9.9.9
P_PREFIX2=/usr/local/lib/

P_FILES3=mcrypt-2.6.8.tar.gz
P_FILES_DIR3=mcrypt-2.6.8
P_PREFIX3=/usr/local/lib/

P_FILES4=php-5.3.28.tar.gz
P_FILES_DIR4=php-5.3.28
P_PREFIX4=/usr/local/php/




if [ -z "$1" ];then
      echo -e "\033[36m请选择下面选项:\033[0m"
      echo -e "\033[32m1)编译安装Apache服务器\033[1m"
      echo "2)编译安装MySQL服务器"
      echo "3)编译安装PHP服务器"
      echo "4)配置index.php并启动LAMP服务"
    echo "5)部署phpMyAdmin系统"
      echo -e "\033[31m使用: { /bin/sh $0 1|2|3|4|help}\033[0m"
      exit
fi


#auto install Apache
if [ $1 -eq 1 ];then
      rpm -e httpd --nodeps
      tar -zxvf $H_FILES &&cd $H_FILES_DIR ;./configure --prefix=$H_PREFIX --enable-so --enable-rewrite --enable-charset-lite --enable-cgi

      if [ $? -eq 0 ];then
                make &&make install
                echo -e "\033[32mThe $H_FILES_DIR Server Install successfully!(Apache服务安装已完成!)\033[0m"
      else
                echo -e "\033[32mThe $H_FILES_DIR Server Install failed,please check...\033[0m"
                exit
      fi
fi

#auto install Mysql
if [ $1 -eq 2 ];then
      rpm -e mysql-server mysql --nodeps
      tar -zxvf cmake-2.8.6.tar.gz -C /usr/src/ && cd /usr/src/cmake-2.8.6/;./configure
      if [ $? -eq 0 ];then
                gmake &&gmake install
                echo -e "\033[32mThe cmake Server Install successfully!(cmake编译安装完成!)\033[0m"
      else
                echo -e "\033[32mThe cmake Server Install failed,please check...\033[0m"
                exit
      fi
      useradd -M -u 27 -s /sbin/nologin mysql
      cd /root
      tar -zxvf $M_FILES -C /usr/src/;cd /usr/src/$M_FILES_DIR && cmake -DCMAKE_INSTALL_PREFIX=$M_PREFIX -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
      if [ $? -eq 0 ];then
                make &&make install
                echo -e "\033[32mThe mysql $M_FILES_DIR Install successfully!(MySQL服务安装已完成!)\033[0m"
      else
                echo -e "\033[32mThe mysql $M_FILES_DIR Install failed,please check...\033[0m"
                exit
      fi
      chown -R mysql:mysql /usr/local/mysql/
      cd /usr/src/$M_FILES_DIR
      cp support-files/my-medium.cnf /etc/my.cnf
      $M_PREFIX/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
      cd /usr/src/$M_FILES_DIR
      ln -s /usr/local/mysql/bin/* /usr/local/bin/
      cp support-files/mysql.server /etc/init.d/mysqld
      chmod +x /etc/rc.d/init.d/mysqld
      chkconfig --add mysqld
      chkconfig mysqld on
      service mysqld stop
      service mysqld start
      netstat -anpt | grep 3306
fi



#PHP define path variable

if [ $1 -eq 3 ];then
      tar -zxvf $P_FILES1 -C /usr/src/;cd /usr/src/$P_FILES_DIR1/ && ./configure && make && make install && ln -s /$P_PREFIX1/libmcrypt.* /usr/lib/
      cd /root/
      tar -zxvf $P_FILES2 -C /usr/src/;cd /usr/src/$P_FILES_DIR2/ && ./configure && make && make install && ln -s /$P_PREFIX2/libmhash* /usr/lib/
      cd /root/
      tar -zxvf $P_FILES3 -C /usr/src/;cd /usr/src/$P_FILES_DIR3/ && export LD_LIBRARY_PATH=/$P_PREFIX3:$LD_LIBRARY_PATH && ./configure && make && make install
      cd /root/
      tar -zxvf $P_FILES4 -C /usr/src/;cd /usr/src/$P_FILES_DIR4/ && ./configure --prefix=$P_PREFIX4 --with-mcrypt --with-apxs2=$H_PREFIX/bin/apxs --with-mysql=$M_PREFIX --with-config-file-path=$P_PREFIX4 --enable-mbstring --enable-sockets
      if [ $? -eq 0 ];then
                make &&make install
                echo -e "\033[32mThe $P_FILES_DIR4 Server Install successfully!(PHP安装已完成!)\033[0m"
      else
                echo -e "\033[32mThe $P_FILES_DIR4 Server Install failed,please check...\033[0m"
                exit
      fi
fi

if [ $1 -eq 4 ];then
      sed -i '/DirectoryIndex/s/index.html/index.php index.html/g' $H_PREFIX/conf/httpd.conf
      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
if [ $1 -eq 5 ];then
      tar -zxvf phpMyAdmin-4.2.5-all-languages.tar.gz
      mv phpMyAdmin-4.2.5-all-languages/ /usr/local/httpd/htdocs/phpMyAdmin
      cd /usr/local/httpd/htdocs/phpMyAdmin
      cp config.sample.inc.php config.inc.php
      if [ $? -eq 0 ];then
                echo -e "\033[32mphpMyAdmin系统安装完成!\033[0m"
      else
                echo -e "\033[31mphpMyAdmin系统安装失败!\033[0m"
      fi

fi

      #netstat -tnl
       # /usr/local/httpd/bin/apachectl -t
      #/usr/local/httpd/bin/apachectl start
      #ps -ef | grep http
         #       echo -e "\033[32m配置完成,打开浏览器测试结果\033[0m"

#phpMyAdmin测试:fireorx http://192.168.1.1/phpMyAdmin &


页: [1]
查看完整版本: LAMP动态网站搭建脚本