#!/bin/bash
echo "LNMP INSTALL NOW"
echo "Update Libs"
yum -y install wget gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
######## install_dir ######
nginx_dir="/usr/local/nginx"
php_dir="/usr/local/php"
mysql_dir="/usr/local/mysql"
######## mysql_user & group #######
groupadd www && useradd www -s /sbin/nologin -g www
useradd -M -s /sbin/nologin mysql
############################################ mysql_install ################################################
cd /packages
tar zxf mysql-5.1.59.tar.gz
cd mysql-5.1.59
CHOST="x86_64-pc-linux-gnu"
CFLAGS="-march=nocona -O2 -pipe"
CXXFLAGS="${CFLAGS}"
./configure "--prefix={$mysql_dir}" "--with-server-suffix=-DZWWW" "--with-mysqld-user=mysql" "--without-debug" "--with-charset=utf8" "--with-extra-charsets=all" "--with-pthread" "--with-big-tables" "--enable-thread-safe-client" "--enable-assembler" "--with-readline" "--with-ssl" "--enable-local-infile" "--with-plugins=partition,myisammrg" "--without-ndb-debug"
make && make install
#########建立配置文件###########
\cp support-files/my-medium.cnf /etc/my.cnf
#########初始化数据库###########
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root.mysql /usr/local/mysql/
chown -R mysql /usr/local/mysql/var
###########调整lib库路径#########
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
ldconfig
###########MYSQL启动配置###########
echo 'start MySQL 5.1.59'
/usr/local/mysql/bin/mysqld_safe --user=mysql &
\cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#cd /usr/local/mysql
#chown -R mysql:mysql.
#rm -rf sql-bench mysql-test
#echo 'config MySQL 5.1.59'
#chmod +w /usr/local/mysql
###########设置MYSQL程序的执行路径##############
export PATH=$PATH:/usr/local/mysql/bin
echo "PATH=$PATH:/usr/local/mysql/bin">> /etc/profile
source /etc/profile
###设置MYSQL密码##
cd ..
echo 'init db MySQL 5.1.59'
sleep 3s
echo 'set password MySQL 5.1.59'
##为mysql设置密码
/usr/local/mysql/bin/mysqladmin -uroot password '123456quanlian'
#sed -i 's#/home/mysql:/bin/bash#/home:/sbin/nologin#' /etc/passwd
echo "mysql server 5.1.59 installed successfully"
/etc/init.d/mysqld start
#将mysql命令设为全局命令,方便管理
ln -s /usr/local/mysql/bin/mysql /sbin/mysql
##################################################### nginx_install #############################################################################
################ 64bit机器,需要安装libunwind, 安装libunwind########
cd /packages
if [ `uname -m` == "x86_64" ];then
#tar zxf libunwind-0.99.tar.gz
tar zxvf libunwind-0.99.tar.gz
cd libunwind-0.99/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
cd ../
else
echo "your system is 32bit ,not install libunwind lib"
fi
cd /packages
tar zxf pcre-8.12.tar.gz
cd /packages/pcre-8.12
./configure
make
make install
cd /packages
tar zxf nginx-1.1.4.tar.gz
cd nginx-1.1.4
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_flv_module --with-http_ssl_module
make && make install
service httpd stop
echo `nginx -t` #####测试是否成功
mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.bak
\cp conf/nginx.conf /usr/local/nginx/conf/nginx.conf
\cp conf/fastcgi.conf /usr/local/nginx/conf/fcgi.conf
echo `nginx -t`
###将nginx设为全局命令,方便管理##
ln -sf /usr/local/nginx/sbin/nginx /sbin/nginx
nginx
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
echo "nginx installed sucussfully"
cd ..
########################################################## php_install ##########################################################
##### phpinstall 组件###########
cd /packages
tar zxf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../
tar zxf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
tar zxf mhash-0.9.9.tar.gz
cd mhash-0.9.9/
./configure
make
make install
cd ../
##########################
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar zxf mcrypt-2.6.7.tar.gz
cd mcrypt-2.6.7/
/sbin/ldconfig
./configure
make
make install
cd ../
################PHP install##############
tar zxf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17/
./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-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
#如果有错误(64bit):则,cp -frp /usr/lib64/libjpeg.* /usr/lib/ ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
cp -frp /usr/lib64/libjpeg.* /usr/lib/
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
cp php.ini-dist /usr/local/php/etc/php.ini
\cp php.ini-dist /usr/local/php/lib/php.ini
cp php-fpm.conf /usr/local/php/etc/
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf.d/mysql_lib.conf
/sbin/ldconfig
/usr/local/php/sbin/php-fpm start
echo "/usr/lcoal/php/sbin/php-fpm" >> /etc/rc.local
echo "php52 installed successfully!"
############### memcache 等扩展安装 #################
cd /packages
tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5/
${php_dir}/bin/phpize
./configure --with-php-config=${php_dir}/bin/php-config
make
make install
cd ../
tar jxf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
${php_dir}/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=${php52_dir}/bin/php-config
make
make install
cd ../
tar zxf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
${php_dir}/bin/phpize
./configure --with-php-config=${php_dir}/bin/php-config --with-pdo-mysql=${mysql_dir}
make
make install
cd ../
#tar zxf ImageMagick.tar.gz
#cd ImageMagick-6.5.1-2/
#./configure
#make
#make install
#cd ../
#tar zxf imagick-2.3.0.tgz
#cd imagick-2.3.0/
#${php_dir}/bin/phpize
#./configure --with-php-config=${php52_dir}/bin/php-config
#make
#make install
#cd ../
#echo "php extension installed successfully!"