shell 一键编译安装lamp

#!/bin/bashphp

#os: centos 6.3  php-5.4.13 mysql-5.6.10 httpd-2.4.3html

#date: 2013/4/27mysql

#author  wusongfulinux

# Make sure the user is rootc++

function rootness(){sql

if [[ $EUID -ne 0 ]]; thenapache

  echo "This script must be run as root" 1>&2centos

  exit 1bash

fiapp

}

#===============================================================================

#DESCRIPTION:disable selinux.

#USAGE:disable_selinux

#===============================================================================

function disable_selinux(){

iptables -F

if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

setenforce 0

fi

}

#the info of  install status

function err(){

if [ $? -ne 0 ] ; then

   echo -e " \n\n\n\t\t\t \033[31m $InApp install false \n\n\n \033[0m"

echo -e " \n\t\t\t \033[31m $InApp install false \n \033[0m" > $Spath/err.info

read -p "do you want to continue [y/n]??"  Ifcontinue

        if [ $Ifcontinue  -e n ] ;then

              exit

        fi



  echo "\n\t\t\t \033[31m continue to install $InApp \n \033[0m"

sleep 2

$1

else

   echo -e " \n\n\n\t\t\t \033[31m $InApp install success \n\n\n \033[0m"

   sleep 1

   cd $Spath

fi

}

#del the exited  app local file

function delDir(){

if [ -e /usr/local/$InApp ] ; then

rm -rf /usr/local/$InApp

fi

}

#uninstall apache php httpd mysql

function removeInstalled(){

if [ -e /etc/httpd ] ; then

rpm -e httpd

rpm -e mysql

rpm -e php

yum -y remove httpd php mysql-server mysql php-mysql

rm -rf /etc/httpd

fi

}

# untar all tar files

function getResource() {

cd $Spath

ls | sed -e '/tar/d' -e '/tgz/d' -e '/-/!d' | xargs  rm -rf

SourceNo=`ls | wc -l `

if [ $SourceNo -ne 11 ] ; then

wget  http://cn2.php.net/distributions/php-5.4.13.tar.gz

wget  http://mirror.cogentco.com/pub/mysql/MySQL-5.6/mysql-5.6.10.tar.gz

wget  http://www.apache.org/dist/httpd/httpd-2.4.3.tar.gz

wget  http://archive.apache.org/dist/apr/apr-1.4.6.tar.gz

wget  http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

wget  http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

wget https://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz

wget https://vps.googlecode.com/files/mcrypt-2.6.8.tar.gz

wget  https://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz

wget  http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-8.32.tar.gz

fi

Tars=`ls | grep .tar. `

for Tar in $Tars ; do

   tar -axvf $Tar

done

}

#install apr

function Iapr(){

InApp=apr

delDir

cd apr-1.4.6

./configure --prefix=/usr/local/apr

make && make install

err Iapr

}

#install apr-util

function IaprU(){

InApp=apr-util

delDir

cd apr-util-1.5.2

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

err  IaprU

}

#install pcre

function Ipcre(){

InApp=pcre

cd pcre-8.32

./configure

make && make install

err Ipcre

}

#install apache

function Iapache(){

InApp=apache

delDir

cd httpd-2.4.3

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/  --enable-so  --enable-dav --enable-deflate=shared --enable-expires=shared  --enable-headers=shared --enable-rewrite --enable-static-support --enable-ssl  --enable-setenvif --with-mpm=prefork --enable-maintainer-mode  --enable-mods-share=all --enable-cache

make && make install

sleep 1


cd  /usr/local/apache/conf

sed -i  '145s/#/ /' httpd.conf

sed -i '226s/Indexes/ /' httpd.conf

sed -i  '233s/None/All/' httpd.conf

sed -i '246s/index.html/index.php index.html /' httpd.conf

sed -i '374a\AddType application/x-httpd-php .php ' httpd.conf

sleep 1

echo "<?php phpinfo(); ?>" > /usr/local/apache/htdocs/index.php


err Iapache

}

#install mysql

function Imysql(){

InApp=mysql

delDir

if [ -e /etc/mysql.cnf ] ; then

rm -rf /etc/mysql.cnf

fi

if [ -e /etc/rc.d/init.d/mysqld ] ; then

rm -rf /etc/rc.d/init.d/mysqld

fi

UserExit=` cat /etc/shadow | grep mysql | wc -l`

if [ $UserExit != 1 ] ; then

/usr/sbin/useradd mysql

fi

cd mysql-5.6.10

cmake .

make && make install

chown -R mysql.mysql /usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

Ifstart=`netstat -tulnp | grep 3306 |wc -l`

if [ $Ifstart == 1 ] ; then

killall mysqld

fi


rm -rf /etc/mysql.cnf

rm -rf /usr/local/mysql/mysql.cnf

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

service mysqld start

err Imysql

}

#ready for php

function Ilibmcrypt(){

InApp=libmcrypt

cd libmcrypt-2.5.8

./configure --prefix=/usr

make && make install

err Ilibmcrypt

}

function Imhash(){

InApp=mhash

cd mhash-0.9.9.9

./configure --prefix=/usr

make && make install

err Imhash

}

function Ilibiconv(){

InApp=libiconv

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make && make install

err Ilibliconv

}

#export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH

function Imcrypt(){

InApp=mcrypt

/sbin/ldconfig

cd mcrypt-2.6.8

./configure

make && make install

err Imcrypt

}

#install php

function Iphp(){

InApp=php

if [ -e /etc/php.ini] ; then

rm -f /etc/php.ini

fi

delDir

cd php-5.4.13

./configure --prefix=/usr/local/php/  --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql  --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --enable-soap --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib  --with-apxs2=/usr/local/apache/bin/apxs  --enable-xml  --with-curl  --enable-fpm --enable-mbstring --with-mcrypt --with-gd  --with-openssl  --with-mhash  --enable-zip  

make && make install

#cp php.ini /usr/local/php/etc/

cp php.ini-development /usr/local/php/etc/php.ini

 sed -i '229s/Off/On/' /usr/local/php/etc/php.ini

sed -i '229s/Off/On/' /etc/php.ini

err Iphp

}

#main function

mkdir -p /var/onekey/tar

Spath="/var/onekey/tar"

rootness

disable_selinux

removeInstalled


# get ready for lamp  yum install  the necessary relevance App

yum -y install gcc gcc-c++ wget cmake make automake ntp autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel  pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils   readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel

#Set timezone

rm -rf /etc/localtime

\cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

[ -d /proc/xen ] && echo "xen.independent_wallclock=1" >>/etc/sysctl.conf && /sbin/sysctl -p && echo "/sbin/ntpdate  cn.pool.ntp.org" >>/etc/rc.local

ntpdate cn.pool.ntp.org

echo "$$" > $Spath/err.info

getResource

#install lamp

Iapr

IaprU

Ipcre

Iapache

Imysql

Ilibmcrypt

Imhash

Ilibiconv

Imcrypt

Iphp