说明:请把所需要的软件包放在文件夹中,把文件夹重命名为packages,然后压缩成packages.zip的包,上传到linux系统上任何目录都可以,然后在上传packages.zip包的当前目录(例如:/media )运行apache_install.sh脚本即可,若apache_install.sh脚本和packages.zip包不在同一目录,需使用绝对该脚本所在绝对路径来运行。
[root@localhost media]# vim /root/apache_install.sh
#!/bin/bash
# Write date: 2012.07.07
date > /root/install_apache_time.txt

#--------------------------------------------------------------------------------
cat << EOF
+--------------------------------------------------------------+
|             === Welcome to install apache ===                |
+--------------------------------------------------------------+
EOF
#---------------------------------------------------------------------------------

# Apache install directory and configuration files...
echo "Do you want to install the apache in what directory?"
read -p "Please input a diretory,For Example:/opt :" directory
#directory=/opt
apache_base_dir=$directory/app/apache
packages=$directory/packages
IN_PATH=`pwd`

# Confirm the source code compilation environment...
gcc --version
if [ $? -eq 0 ]
 then
  echo "gcc installed!!"
 else
  yum -y install gcc*
fi
g++ --version
if [ $? -eq 0 ]
 then
  echo "g++ installed!!"
 else
  yum -y install g++*
fi

# Check the httpd rpm packages installed...
rpm -qa | grep httpd
if [ $? -eq 0 ]
 then
  echo "The httpd rpm packages already installed!!"
  echo "# yum -y remove httpd"
  service httpd stop
  sleep 5
  yum -y remove httpd
 else
  echo "The httpd rpm packages not installed!!"
fi

unzip $IN_PATH/packages.zip -d $directory
# Apache version choice...
echo "show $packages apache(httpd) install package."
ls -lh $packages | awk '{ print $9}' | grep httpd
echo "Please input you will install Apache version number:"
read -p "Apache version number is:" version
echo "You will install Apache package is httpd-$version.tar.gz!"
sleep 5
echo "show $packages apache install package."
if [ -e "$packages/httpd-$version.tar.gz" ]
 then
  # Create the installation directory...
  if [ -d "$apache_base_dir" ]
   then
    echo "This $apache_base_dir is already existed!"
   else
    echo "The $apache_base_dir is create now."
    mkdir -p $apache_base_dir
   fi
  echo "Please wait..."
# Unpack, configure, compile, install apache
  echo "Unpack, configure, compile, install apache."
  tar -zxf $packages/httpd-$version.tar.gz -C $packages
  cd $packages/httpd-$version
  sh configure \
     --prefix=$apache_base_dir \
     --enable-so \
     --enable-rewrite \
     --enable-ssl \
     --with-ssl=/usr/lib \
     --enable-auth-digest \
     --enable-cgi \
     --enable-suexec \
     --with-suexec-caller=daemon \
     --with-suexec-docroot=$apache_base_dir/htdocs
  make && make install
  cd /root
  $apache_base_dir/bin/apachectl start
  echo $apache_base_dir/bin/apachectl start >> /etc/rc.local
  echo "Show Apache used port!!"
  netstat -antupl | grep httpd
  echo "The apache install Success!!!"
  cat << EOF
   +--------------------------------------------------------------+
|               === The apache install Success!!! ===                |
   +--------------------------------------------------------------+
EOF
  date >> /root/install_apache_time.txt
  echo "Show time to install Apache!!"
  cat /root/install_apache_time.txt | awk '{ print $4 }'
 else
  echo "The apache install Failed!!!"
  rm -fr $apache_base_dir
  rm -fr $packages
  rm -f /root/install_apache_time.txt
fi

[root@localhost media]# chmod 755 /root/apache_install.sh
[root@localhost media]# /root/apache_install.sh