#!/bin/bash# 安装依赖包yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel epel-release libmcrypt-devel autoconf epel-release libmcrypt libmcrypt-devel# 准备php安装包cd /usr/local/src/ || exitwget http://cn2.php.net/distributions/php-5.6.32.tar.gztar zxvf php-5.6.32.tar.gz# 添加用户useradd -s /sbin/nologin php-fpm# 编译安装cd php-5.6.32 || exit./configure --prefix=/usr/local/php --sysconfdir=/usr/local/php/etc --with-config-file-path=/usr/local/php/etc/ --with-fpm-user=php-fpm --with-fpm-group=php-fpm --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --enable-zip --with-pcre-dir --with-pear --enable-session --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-soap --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --enable-ftp --enable-redisif [ $? -ne 0 ] ; then yum -y install epel-release libmcrypt libmcrypt-devel # 前面yum安装指定了这三个包,也有时候安装不了,导致预编译出错。为了避免,这里再安装一遍fimake && make installif [ $? -ne 0 ] ; then echo "无法安装!" exit 1fi# 从安装包里拷贝生产环境的配置文件到php目录下cp php.ini-production /usr/local/php/etc/php.ini# 准备启动脚本,启动php-fpm并设置php-fpm开机自启cp /usr/local/src/php-5.6.32/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmmv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confchmod 755 /etc/init.d/php-fpmchkconfig --add php-fpmservice php-fpm startchkconfig php-fpm on# 添加到环境变量中sed -i '$a export PATH=/usr/local/php/bin:$PATH' /etc/profilesource /etc/profile