LAMP一鍵安裝腳本

#!/bin/sh
#Copyright(c) 2010-2015 redapple ([email protected]) 
#install LAMP 
#Version 0.1.1
#Date 20140813
#------------增加yum源------------------------
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#------------安裝gcc------------------------
yum install gcc-c++  gcc ncurses-devel wget openssl openssl-devel zlib-devel unzip -y
#--------------時間同步--------------------
ntpdate tiger.sina.com.cn
hwclock -w
service iptables stop
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
yum -y remove httpd php mysql-server mysql php-mysql
installLog="/root/instlog.log"
function checkLog(){
[ $? -eq 0 ] && echo "Successfull! " || echo "configure is error,pls check it." && [ -f $installLog ] && tail -30 $installLog && exit 1 
}
function msg(){
echo -n "now,Scripts is '$1' apache, this maybe take several mins, pls wait..."
}
function apr_err {
cd ..
[ ! -f apr-1.4.5.tar.gz ] && wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz  
[ ! -f apr-util-1.3.12.tar.gz ] && wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz  
[ ! -f pcre-8.10.zip ] && wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip  
yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs -y
tar -zxf apr-1.4.5.tar.gz 
#cd  apr-1.4.5
#./configure --prefix=/usr/local/apr  
#make && make install
#cd ..
tar -zxf apr-util-1.3.12.tar.gz  
#cd apr-util-1.3.12  
#./configure --prefix=/usr/local/apr-util -with- apr=/usr/local/apr/bin/apr-1-config  
#make && make install
[ ! -d ./httpd-2.4.10/srclib ] && echo "flies install err " && exit
\cp -rf ./apr-1.4.5  ./httpd-2.4.10/srclib/apr
\cp -rf ./apr-util-1.3.12   ./httpd-2.4.10/srclib/apr-util
unzip -o pcre-8.10.zip  
cd pcre-8.10 
./configure --prefix=/usr/local/pcre >>$installLog 
[ $? != 0 ] && echo "ERROR: pcre configure err" && checkLog
make && make install
cd ..
cd httpd-2.4.10
./configure \
--prefix=/usr/local/apache \
--with-included-apr \
--enable-so \
--with-mpm=prefork \
--enable-deflate=shared \
--enable-expires=shared \
--enable-headers=shared \
--enable-rewrite=shared \
--enable-static-support \
--with-crypto \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre=/usr/local/pcre >>$installLog
[ $? != 0 ] && echo "ERROR: Apache configure err" && checkLog
}
#----------------下載安裝Apache------------------
groupadd apache 
useradd -g apache -s /usr/sbin/nologin apache  
chown -R apache:apache /usr/local/apache 
[ ! -f httpd-2.4.10.tar.gz ] && wget http://apache.fayea.com/apache-mirror/httpd/httpd-2.4.10.tar.gz
tar xf httpd-2.4.10.tar.gz
cd httpd-2.4.10
./configure \
--prefix=/usr/local/apache \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-headers=shared \
--enable-rewrite=shared \
--enable-static-support \
--with-mpm=prefork >>$installLog
[ $? != 0 ] && echo "ERROR: Apache configure err" && apr_err
msg make
make 2>&1
[ $? != 0 ] &&  echo "ERROR: Apache make err"
msg 'make install'
make install 2>&1
[ $? != 0 ] &&  echo "ERROR: Apache install err"
\cp ./build/rpm/httpd.init /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
chkconfig --add httpd  
chkconfig --level 2345 httpd on  
chkconfig --list httpd 
mv /etc/httpd  /etc/httpd_old
ln -fs /usr/local/apache/ /etc/httpd
ln -fs /usr/local/apache/bin/httpd /usr/sbin/httpd
ln -fs /usr/local/apache/bin/apachectl /usr/sbin/apachectl
rm -rf /var/log/httpd/  
ln -s /usr/local/apache/logs  /var/log/httpd  
sed -i '/#ServerName/a\ServerName localhost' /usr/local/apache/conf/httpd.conf
chown -R apache:apache /usr/local/apache
service  httpd start
ps -ef | grep httpd
echo "=============apache install OK !!!!============"
sleep 3
#----------------下載安裝mysql------------------
cd ..
yum install cmake ncurses-devel -y
groupadd mysql
useradd -g mysql mysql -s /bin/false
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
[ ! -f mysql-5.5.38.tar.gz ] && wget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.38.tar.gz
tar xf mysql-5.5.38.tar.gz 
cd mysql-5.5.38
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_unicode_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0
[ $? != 0 ] && exit
make && make install
[ -f /etc/my.cnf ] && rm -rf /etc/my.cnf
cp support-files/my-medium.cnf  /etc/my.cnf
sed -i 's#max_allowed_packet = 1M#max_allowed_packet = 16M#' /etc/my.cnf
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
[ -f /etc/init.d/mysqld ] && rm -rf /etc/init.d/mysqld
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i '46s#basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
sed -i '47s#datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile 
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
service mysqld start
ps -ef |grep mysqld
echo "=============MYSQL install OK !!!!============"
#----------------下載並安裝freetype------------------
cd ..
[ ! -f freetype-2.5.3.tar.gz ] && wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz
tar -zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure --prefix=/usr/local/freetype
make && make install
#----------------下載並安裝libmcrypt------------------
cd ..
[ ! -f libmcrypt-2.5.7.tar.gz ] && wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure    
make && make install
#----------------解決可能出現的libiconv錯誤------------------
[ ! -f libiconv-1.14.tar.gz ] && wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xzf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
#----------------下載並安裝jpegsrc.v9------------------
cd ..
[ ! -f jpegsrc.v9a.tar.gz ] && wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz
tar -xf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg
make && make install
#----------------下載並安裝php------------------
cd ..
yum install -y libcurl bzip2-devel bzip2 libxml2-devel curl curl-devel gd libpng zlib
#---想讓編譯的php支持mcrypt、mhash擴展和libevent---------
#yum install libmcrypt libmcrypt-devel mhash mhash-devel mcrypt
[ ! -f php-5.5.15.tar.gz ] && wget http://cn2.php.net/distributions/php-5.5.15.tar.gz
tar xf php-5.5.15.tar.gz
cd php-5.5.15
./configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-openssl \
--enable-sockets \
--enable-sysvshm  \
--enable-xml  \
--enable-mbstring \
--enable-bcmath \
--enable-soap  \
--enable-shmop \
--enable-sysvsem \
--enable-pcntl \
--enable-zip \
--enable-fastcgi \
--enable-gd-native-ttf \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-iconv=/usr/local/libiconv \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-freetype-dir=/usr/local/freetype \
--with-jpeg-dir=/usr/local/jpeg \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir=/usr \
--with-mhash \
--with-mcrypt  \
--with-gettext \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--with-curl \
--with-xmlrpc \
--without-pear  
[ $? != 0 ] && exit
make && make install
cp ./php.ini-production /usr/local/php/etc/php.ini
sed -i 's#;date.timezone =#date.timezone = PRC#' /etc/php.ini
sed -i 's#expose_php = On#expose_php = OFF#' /etc/php.ini
sed -i '/AddType text\/html .shtml/aAddType application\/x-httpd-php .php\n' /etc/httpd/conf/httpd.conf
service  httpd restart
ps -ef | grep httpd
#----------------新建index.php的測試頁面------------------
cat > /var/www/html/index.php << EOF
<?php
phpinfo();
?>
EOF
echo "=============PHP install OK !!!!============"
echo "=============LAMP install OK !!!!============"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章