#!/bin/bash
PATH=`echo $PATH`
### auther xiao song lin##
##date 2013 06 13
##LAMP ###
#set yum server
setyum () {
#if [ -f /etc/yum.repos.d/*.repo ];
# then
rm -rf /etc/yum.repos.d/*
echo "[RHEL]" > /etc/yum.repos.d/RHEL.repo
echo "name=RHEL" >> /etc/yum.repos.d/RHEL.repo
echo "baseurl=http://192.168.18.254/5.4/Server" >> /etc/yum.repos.d/RHEL.repo
echo "enabled=1" >> /etc/yum.repos.d/RHEL.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/RHEL.repo
sleep 3
yum clean all
yum update
if [ $? -eq 0 ];
then
echo "yum set ok" > /dev/null
else
echo "yum set ERROR"
exit 10
fi
# fi
}
##httpd
httpd () {
if [ -f /etc/init.d/httpd ];then rpm -e httpd-* --nodeps;fi
mkdir -pv /usr/local/src/lamp
cd /usr/local/src/lamp
wget ftp://192.168.18.254/pub/apr-1.4.6.tar.bz2
wget ftp://192.168.18.254/pub/apr-util-1.5.1.tar.bz2
wget ftp://192.168.18.254/pub/httpd-2.4.3.tar.gz
if [ $? -ne 0 ];then echo "wget was fail";exit10;fi
tar fvxj apr-1.4.6.tar.bz2
cd apr-1.4.6
./configure --prefix=/usr/local/apr
make && make install
if [ $? -ne 0 ];then echo "make apr was fail";exit10;fi
cd ..
tar fvxj apr-util-1.5.1.tar.bz2
cd apr-util-1.5.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make install
if [ $? -ne 0 ];then echo "make apr-util was fail";exit10;fi
cd ..
tar fvxz httpd-2.4.3.tar.gz
yum install zlib-devel gcc gcc-c++ openssl-devel pcre-devel -y
if [ $? -ne 0 ];then echo "install was fail or already instll" >/tmp/install.log;fi
cd httpd-2.4.3
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-module=so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-ab --disable-userdir --with-mpm=prefork --enable-nonportable-atomics --disable-ipv6 --with-sendfile
make && make install
if [ $? -ne 0 ];then echo "make was fail";exit10;fi
/usr/local/apache2/bin/apachectl -k start
}
##install mysql
mysql () {
rpm -qa |grep mysql*
if [ $? -eq 0 ];then rpm -e mysql* --nodeps;fi
cd /usr/local/src/lamp
wget ftp://192.168.18.254/pub/cmake-2.6.4-7.el5.i386.rpm
wget ftp://192.168.18.254/pub/mysql-5.5.29.tar.gz
if [ $? -ne 0 ];then echo "wget was fail";exit10;fi
rpm -ivh cmake-2.6.4-7.el5.i386.rpm
groupadd mysql
useradd -g mysql mysql
yum install gcc gcc-c++ ncurses-devel libtool openssl-devel -y
if [ $? -ne 0 ];then echo "install mysqlgcc was fail or already instll" >/tmp/install.log;fi
mkdir -pv /usr/local/mysql/data
tar fzvx mysql-5.5.29.tar.gz
cd mysql-5.5.29
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data/ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DWITH_INNODBBASE_STORAGE_ENGINE=1 \
-DENABLE_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_EMBEDED_SERVER=0
make && make install
if [ $? -ne 0 ];then echo "make mysql was fail";exit10;fi
cp support-files/my-medium.cnf /etc/my.cnf
echo "skip-name-resolve=1" >>/etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqlsource
chmod 755 /etc/init.d/mysqlsource
chown mysql.mysql /usr/local/mysql/ -R
sh scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
ln -s /usr/local/mysql/bin/* /usr/bin/
ln -s /usr/local/mysql/lib/* /usr/lib/
ln -s /usr/local/mysql/libexec/* /usr/local/libexec
ln -s /usr/local/mysql/share/man/man1/* /usr/share/man/man1
ln -s /usr/local/mysql/share/man/man8/* /usr/share/man/man8
/etc/init.d/mysqlsource start
/usr/local/mysql/bin/mysqladmin -u root password '123123'
}
###php
php () {
#cat <<EOF
rpm -qa |grep php-*
if [ $? -eq 0 ];then rpm -e php-* --nodeps;fi
cd /usr/local/src/lamp
yum install libxml2-devel bzip2-devel net-snmp-devel curl-devel libpng-devel freetype-devel libjpeg-devel zlib-devel -y
if [ $? -ne 0 ];then echo "install php was fail or already instll" >/tmp/install.log;fi
wget ftp://192.168.18.254/pub/bao/bao/libiconv-1.14.tar.gz
wget ftp://192.168.18.254/pub/bao/bao/libmcrypt-2.5.8.tar.gz
wget ftp://192.168.18.254/pub/bao/bao/mhash-0.9.9.9.tar.gz
wget ftp://192.168.18.254/pub/bao/bao/mcrypt-2.6.8.tar.gz
wget ftp://192.168.18.254/pub/php-5.4.11.tar.bz2
if [ $? -ne 0 ];then echo "wget was fail";exit10;fi
tar fvxz libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/ --with-apr=/usr/local/apr
make && make install
if [ $? -ne 0 ];then echo "make phplib was fail";exit10;fi
######libmcrypt-2.5.8.tar.gz
cd ..
tar fvxz libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure && make && make install && /sbin/ldconfig
if [ $? -ne 0 ];then echo "make phplibm was fail";exit10;fi
cd libltdl/
./configure --enable-ltdl-install && make && make install
if [ $? -ne 0 ];then echo "make phpliblt was fail";exit10;fi
######mhash-0.9.9.9.tar.gz
cd ..
cd ..
tar fvxz mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
if [ $? -ne 0 ];then echo "make phpmhast was fail";exit10;fi
ln -s /usr/local/lib/* /usr/lib/
ln -s /usr/local/bin/libmcrypt-config /usr/bin/
#####mcrypt-2.6.8.tar.gz
cd ..
tar fvxz mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure && make && make install
if [ $? -ne 0 ];then echo "make phpmcry was fail";exit10;fi
##install php
cd ..
tar fvxj php-5.4.11.tar.bz2
cd php-5.4.11
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-iconv-dir=/usr/local/ --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --with-pcre-regex --with-zlib --with-bz2 --enable-calendar --disable-phar --with-curl --enable-dba --with-libxml-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt --enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip --enable-bcmath --with-snmp --disable-ipv6 --disable-rpath --disable-debug --with-apxs2=/usr/local/apache2/bin/apxs
./configure --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
make ZEND_EXTRA_LIBS='-liconv'
make install
if [ $? -ne 0 ];then echo "make php was fail";exit10;fi
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/apache2/conf
sed -i 's/DirectoryIndex index.html/& index.php/g' httpd.conf
echo "Addtype application/x-httpd-php .php " >>httpd.conf
killall httpd
/usr/local/apache2/bin/apachectl -k start
cd /usr/local/apache2/htdocs/
echo "<?php phpinfo(); ?> " >phpinfo.php
}
########
##main####
case $1 in
setyum) setyum;;
htt) httpd;;
my) mysql;;
p) php;;
*) echo "Usage sh lamp.sh install|start|restart|stop|status|test";;
esac
###
若复制发生如下的情况;
这种情况发生的原因是因为你所处理的文件换行符是dos格式的"\r\n"
可以使用cat -v 文件名 来查看换行符是否是,如果是上述的,则行结尾会是^m
需要转换成linux/unix格式的"\n"
具体转换办法就是转换换行符
可以用sed命令处理一下文件,命令如下:
sed 's/\r//' 原文件 >转换后文件