#php编译安装php-5.6 ,Nginx+php使用
#!/bin/sh
#php编译安装php-5.6 ,Nginx+php使用 #定义函数,默认绿色输出 '#' 开头为红色
function echocolor()
{
[[ $ = '#' ]] && echo -e "\033[31m $* \033[0m" || echo -e "\033[32m $* \033[0m"
}
#检测网络
ping baidu.com -c &>/dev/null || ping qq.com -c &>/dev/null || { echocolor '#' "网络异常!";exit; } #设置yum 安装包不删除 目录 /var/cache/yum/
#sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf echocolor '#安装需要的库'
yum install epel-release -y
yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel libjpeg-devel libpng-devel libicu-devel openldap-devel ftp -y echocolor "#设置目录"
Ddir=/it/tools #下载目录
Sdir=/www/server #安装目录
[ -d $Ddir ] || mkdir -p $Ddir
[ -d $Sdir/php ] || mkdir -p $Sdir/php/etc
#[ -d $Sdir/apache/bin/apxs ] || mkdir -p $Sdir/apache/bin/apxs
##下载
wget http://cn2.php.net/distributions/php-5.6.31.tar.gz -P $Ddir/ echocolor "添加用户"
useradd -s /sbin/nologin -M www
id www echocolor "解压"
[ -e $Ddir/php-5.6*.tar.gz ] && { tar xzvf $Ddir/php-5.6*.tar.gz -C $Ddir/;cd $Ddir/php-5.6*; } || { echocolor '#' "$Ddir目录无php-5.6源码包";exit ; } # [ `uname -m` = "x86_64" ] && LIB=/usr/lib64 || LIB=/usr/lib64
# --with-apxs2=/usr/local/apache/bin/apxs #编译参数,apache+php使用
make clean
echocolor 编译
./configure \
--prefix=$Sdir/php \
--with-config-file-path=$Sdir/php/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--enable-ftp \
--with-ldap-dir=/usr/lib \
--with-png-dir=/usr/lib \
--with-jpeg-dir=/usr/lib \
--with-readline [ $? = ] || { echocolor '#' "编译出现问题 !";exit; }
echocolor 编译安装
make -j4 && make install
# make clean
# make clean all #配置PHP
cp php.ini-production $Sdir/php/etc/php.ini
cp $Sdir/php/etc/php-fpm.conf.default $Sdir/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm $Sdir/php/bin/php-fpm
chmod +x $Sdir/php/bin/php-fpm
ln -s $Sdir/php/bin/php-fpm /etc/init.d/php-fpm
# ln -s $Sdir/php/etc/php-fpm.conf /etc/php-fpm.conf
# ln -s $Sdir/php/etc/php.ini /etc/php.ini
chkconfig --add php-fpm
chkconfig php-fpm on
chkconfig --list php-fpm
#service php-fpm start
#显示版本
$Sdir/php/bin/php -v
#重启
service php-fpm restart
netstat -antp|grep php-fpm