#!/bin/bash
#auto make install LAMP
#by authors yehailun

#arp和apr-util依赖
APR_FILES=apr-1.6.2.tar.gz
APR_FILES_DIR=/usr/local/src/apr-1.6.2
APR_URL=http://mirrors.ustc.edu.cn/apache/apr
APR_PREFIX=/usr/local/apr

APR_UTIL_FILES=apr-util-1.6.0.tar.gz
APR_UTIL_FILES_DIR=/usr/local/src/apr-util-1.6.0
APR_UTIL_URL=http://mirrors.ustc.edu.cn/apache/apr
APR_UTIL_PREFIX=/usr/local/apr-util

#pcre
PCRE_FILES=pcre-8.37.tar.gz
PCRE_FILES_DIR=/usr/local/src/pcre-8.37
PCRE_URL=https://nchc.dl.sourceforge.net/project/pcre/pcre/8.37
PCRE_PREFIX=/usr/local/pcre

#Http define path variable
H_FILES=httpd-2.4.27.tar.gz
H_FILES_DIR=/usr/local/src/httpd-2.4.27
H_URL=http://mirrors.sohu.com/apache
H_PREFIX=/usr/local/apache

#MySQL define path variable
M_FILES=mysql-5.6.36.tar.gz
M_FILES_DIR=/usr/local/src/mysql-5.6.36
M_URL=http://mirrors.sohu.com/mysql/MySQL-5.6
M_PREFIX=/usr/local/mysql/

#PHP define path variable
P_FILES=php-5.6.13.tar.gz
P_FILES_DIR=/usr/local/src/php-5.6.13
P_URL=http://mirrors.sohu.com/php/
P_PREFIX=/usr/local/php

if [ -z "$1" ];then
echo -e "\033[32m Please Select Install Menu follow: \033[1m"
echo -e "1)安装依赖包"
echo -e "2)编译安装Apache服务器"
echo -e "3)编译安装MySQL服务器"
echo -e "4)编译安装PHP服务器"
echo -e "5)配置index.php并启动LAMP服务"
echo -e "\033[31m Usage:{ /bin/sh $0 1|2|3|4|5|help} \033[0m"
fi

if [[ "$1" -eq "1" ]];then
yum groupinstall "Development Tools" "Development Libraries" -y
yum install gcc gcc-c++ openssl-devel expat-devel -y

#Install apr
wget -c $APR_URL/$APR_FILES && tar -zxvf $APR_FILES -C /usr/local/src && cd $APR_FILES_DIR; ./configure --prefix=$APR_PREFIX
if [ $? -eq 0 ];then
make -j 4 && make install && cd
echo -e "\033[32m The Apr Install Successfully! \033[0m"
else
echo -e "\033[32m The Apr Install Failed,Please check! \033[0m"
exit
fi

#Install apr-util
wget -c $APR_UTIL_URL/$APR_UTIL_FILES && tar -zxvf $APR_UTIL_FILES -C /usr/local/src && cd $APR_UTIL_FILES_DIR; ./configure --prefix=$APR_UTIL_PREFIX --with-apr=$APR_PREFIX
if [ $? -eq 0 ];then
make -j 4 && make install && cd
echo -e "\033[32m The Apr-util Install Successfully! \033[0m"
else
echo -e "\033[32m The Apr-util Install Failed,Please check! \033[0m"
exit
fi

#Install pcre
wget -c $PCRE_URL/$PCRE_FILES && tar -zxvf $PCRE_FILES -C /usr/local/src && cd $PCRE_FILES_DIR; ./configure --prefix=$PCRE_PREFIX
if [ $? -eq 0 ];then
make -j 4 && make install && cd
echo -e "\033[32m The Pcre Install Successfully! \033[0m"
echo -e "\033[32m All Dependency Packages Are Installed Successfully! \033[0m"
else
echo -e "\033[32m The Pcre Install Failed,Please check! \033[0m"
exit
fi
fi

#Install Httpd Server
if [[ "$1" -eq "2" ]];then
wget -c $H_URL/$H_FILES && tar -zxvf $H_FILES -C /usr/local/src && cd $H_FILES_DIR ; ./configure --prefix=$H_PREFIX --enable-so --enable-rewrite --enable-ssl --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event

if [ $? -eq 0 ];then
make -j 4 && make install && cd
echo -e "\033[32m The Httpd Server Install Successfully! \033[0m"
chown -R apache:apache /usr/local/apache/
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
sed -i "9a # chkconfig:2345 64 36" /etc/init.d/httpd
sed -i "197a ServerName localhost:80" /usr/local/apache/conf/httpd.conf
useradd -M -s /sbin/nologin apache
sed -i "s/^User/User apache/g" /usr/local/apache/conf/httpd.conf
sed -i "s/^Group/Group apache/g" /usr/local/apache/conf/httpd.conf
chkconfig --add httpd
service httpd start
else
echo -e "\033[32m The Httpd Server Install Failed,Please check! \033[0m"
exit
fi
fi

#Install MySQL
if [[ "$1" -eq "3" ]];then
yum remove -y mysql mysql-server
rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
yum install -y cmake ncurses-devel;
useradd -M -s /sbin/nologin mysql
wget -c $M_URL/$M_FILES && tar -zxvf $M_FILES -C /usr/local/src && cd $M_FILES_DIR
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL-USER=mysql
if [ $? -eq 0 ];then
make -j 4 && make install && cd
else
echo -e "\033[32m The MySQL Server Install Failed,Please check! \033[0m"
exit
fi
chown -R mysql:mysql /usr/local/mysql/
/bin/cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
/bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i 's%^basedir=%basedir=/usr/local/mysql%' /etc/init.d/mysqld
sed -i 's%^datadir=%datadir=/usr/local/mysql/data%' /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
/usr/local/mysql/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/usr/local/mysql/ \
--datadir=/usr/local/mysql/data/ \
--user=mysql
if [ $? -eq 0 ];then

echo -e "033[32m The MySQL Server Install Successfully! \033[0m"
ln -s /usr/local/mysql/bin/* /bin/
service mysqld start
else
echo -e "033[32mThe MySQL Server Install Failed,Please check!\033[0m"
exit
fi
fi

#Install PHP Server
if [[ "$1" -eq "4" ]];then
yum install -y libxml2-devel
wget -c $P_URL/$P_FILES && tar -zxvf $P_FILES -C /usr/local/src && cd $P_FILES_DIR &&./configure --prefix=$P_PREFIX --with-apxs2=$H_PREFIX/bin/apxs --with-config-file-path=$P_PREFIX --with-mysql=$M_PREFIX
if [ $? -eq 0 ]; then
make && make install && cd $P_FILES_DIR
cp php.ini-production /usr/local/php/php.ini ; cd
echo -e "\033[32m The PHP Install Successfully! \033[0m"
else
echo -e "\033[32m The PHP Install Failed,Please check! \033[0m"
exit
fi
fi

#Start LAMP SERVICE
if [[ "$1" -eq "5" ]];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
service httpd restart
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
service httpd restart
fi

shell脚本自动化安装LAMP的更多相关文章

  1. shell脚本自动化安装pgsql10.5版本

    看到有个大佬写了个很实用的脚本,于是这里做了转载 #!/bin/bash #进入软件的制定安装目录 echo "进入目录/usr/local,下载pgsql文件" cd /usr/ ...

  2. shell脚本编译安装LAMP环境

    #filename lamp.sh#version Centos6.7;apache2.4.23;mariadb-5.5.40;php5.5.38#data 2016/09/28#mail 23853 ...

  3. fdisk分区硬盘并shell脚本自动化

    最近工作需要用到对硬盘进行shell脚本自动化分区和mount的操作,google了一些资料,下面做个总结. 如果硬盘没有进行分区(逻辑分区或者扩展分区,关于两者概念,自行google),我们将无法将 ...

  4. Centos 6.4上面用Shell脚本一键安装vsftpd

    Centos 6.4上面用Shell脚本一键安装vsftpd install.sh #!/bin/bash if [ `uname -m` == "x86_64" ];then m ...

  5. Centos 6.4上面用Shell脚本一键安装mysql 5.6.15

    Centos 6.4上面用Shell脚本一键安装mysql 5.6.15  #!/bin/bash if [ `uname -m` == "x86_64" ];then machi ...

  6. shell脚本自动化部署服务

    shell脚本自动化部署 !/bin/bash #export PATH=$PATH:/export/maven/bin run_flag_dir="/data0/shell/deploy_ ...

  7. 安装完Ubuntu后通过shell脚本一键安装软件

    安装完Ubuntu后通过shell脚本一键安装软件 以下代码中#是单行注释 :<<! ! 是多行注释. 运行的时候需要把多行注释去掉. 比如把以下代码保存为install.sh, 那么在终 ...

  8. shell脚本自动化部署

    由于公司技术部团队较小,没有专门的运维团队,所以运维工作技术部承包了. 一.纯人工部署是这样的: 1. 本地打包:一般 maven clean package 2. 借助xftp上传到服务器对应目录 ...

  9. 脚本实现自动化安装lamp&lnmp

    #备注:前提是将lnmp和lnmp自动化脚本写好放在相应的路径, 脚本已写好,请查看我博客中的 shell脚本 专栏! #!/bin/bash #安装lamp或者lnmp path=/server/s ...

随机推荐

  1. Spring之i18n配置与使用

    Spring的i18n配置: <!-- conf:i18n --> <bean id="messageSource" class="org.spring ...

  2. OpenGL核心之视差映射

    笔者介绍:姜雪伟,IT公司技术合伙人.IT高级讲师,CSDN社区专家,特邀编辑.畅销书作者;已出版书籍:<手把手教你¯的纹理坐标偏移T3来对fragment的纹理坐标进行位移.你能够看到随着深度 ...

  3. [Angular] Scrolling the Message List To the Bottom Automatically Using OnChanges

    Let's say the message list can Input (messages) from parent component, and what we want to do is whe ...

  4. [Recompose] When nesting affects Style

    In CSS we use the descendant selector to style elements based on their nesting. Thankfully in React ...

  5. Qt 连接MySQL数据库(很多相关文章)

    今天想试试Qt如何连接数据库的. 谁知怎么写完了提示driver not loaded我就郁闷了. 我自己是 VS2010 + Qt4.8.4 + MySQL5.1 的环境 网上查到是 C:\Qt\4 ...

  6. 概念的理解 —— 奇点(singularity point)、第一性原理(first principle)

    奇点(singularity point)一词出现在不同的环境里,对应着不同的含义: wikipedia:Singularity 文艺作品: 未来学(Futurology):比如雷·库兹韦尔的< ...

  7. 小强的HTML5移动开发之路(31)—— JavaScript回顾6

    HTML DOM模型: w3c dom 模型(规范)出现之前,各个浏览器自己支持的一些dom操作 Select对象 属性: selectedIndex:表示用户现在选择的那个选项的下标(从0开始) l ...

  8. ScrollView嵌套ListView问题

    ScrollView嵌套ListView问题 导致Listview  第一主角 它是 Listview 的item 显示器的数量是不完全. 这是因为item 中间 Textview 话是太多的问题 一 ...

  9. Tricks(四十八)—— 注释一段代码

    为 if 的条件判断表达式,传一个永假的语句,来注释一段代码: # Python if False: ... ... ... # C/C++ if (false) { ... ... } 永远不要直接 ...

  10. 怎么样Windows7在配置ASPserverIIS

    在百度经验浏览:http://jingyan.baidu.com/article/5553fa82ed97c765a23934f3.html Internet Information Services ...