码迷,mamicode.com
首页 > Web开发 > 详细

php编译安装脚本

时间:2016-09-02 23:38:43      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:php编译安装脚本

#!/bin/bash
DIR=$( cd "$( dirname "$0" )" && pwd )
SRCDIR=/usr/local/src
phpVersion="5.6.25"
phpUser=www
phpGroup=www
if [ $(id -u) -ne 0 ]; then
        echo "Please run as root"
        exit 1
fi
DISTRO=""
Distributions="CentOS Ubuntu Red"
for i in $Distributions
do
        cat /etc/*-release |grep "$i" >/dev/null
        if [ $? -eq 0 ]; then
                DISTRO=$i
        fi
done
egrep "^$phpGroup" /etc/group >/dev/null
if [ $? -ne 0 ]; then
        groupadd $phpGroup
fi
egrep "^$phpUser" /etc/passwd >/dev/null
if [ $? -ne 0 ]; then
        [ $DISTRO = "CentOS" -o $DISTRO = "Red" ] && useradd -g $phpGroup -s /sbin/nologin -M -r $phpUser
fi

function install_php {
        cd $SRCDIR
        [ ! -f php-$phpVersion.tar.gz ] && curl http://cn2.php.net/distributions/php-$phpVersion.tar.gz -o php-$phpVersion.tar.gz
        tar zxf php-$phpVersion.tar.gz
        cd php-$phpVersion
        [ $DISTRO = "CentOS" ] && yum install -y epel-release
        if [ $DISTRO = "Amazon" -o $DISTRO = "CentOS" -o $DISTRO = "Red" ]; then
                yum -y groupinstall "X Software Development"
                yum install -y gcc gcc-c++ openssl-devel libxml2-devel libcurl-devel zlib-devel libmcrypt-devel mhash-devel bzip2-devel libicu-devel libpng-devel libjpeg-devel freetype-devel openldap-devel readline-devel autoconf libevent libevent-devel mcrypt
        #       yum install -y httpd-devel perl
                ./configure                 --prefix=/usr/local/php-$phpVersion                 --with-config-file-path=/usr/local/php-$phpVersion/etc                 --with-fpm-user=$phpUser                 --with-fpm-group=$phpGroup         #       --with-apxs2                --disable-rpath                 --enable-fpm                 --enable-inline-optimization                 --enable-shared                 --enable-opcache                 --enable-pcntl                 --enable-shmop                 --enable-sysvmsg                 --enable-sysvsem                 --enable-sysvshm                 --enable-mbstring             
                --enable-sockets                 --enable-soap                 --enable-zip                 --enable-calendar                 --enable-bcmath                 --enable-exif                 --enable-intl                 --enable-xml                 --enable-mysqlnd                 --with-libdir=lib64                 --with-mysql=mysqlnd                 --with-mysqli=mysqlnd                 --with-pdo-mysql=mysqlnd                 --with-openssl                 --with-zlib                 --with-bz2                 --with-curl                 --with-gd                 --with-jpeg-dir                 --with-zlib-dir                 --with-png-dir                 --enable-gd-native-ttf                 --with-freetype-dir                 --with-gettext                 --with-iconv                 --with-mcrypt                 --with-mhash                 --with-ldap                 --with-readline && make && make install
                retval=$?
        fi
        return $retval
}

function config_php {
cd $SRCDIR
cd php-$phpVersion
cp php.ini-development /usr/local/php-$phpVersion/etc/php.ini
sed -i ‘/^;date.timezone/ {s/.*/;date.timezone = PRC/g}‘ /usr/local/php-$phpVersion/etc/php.ini
sed -i ‘/fix_pathinfo=1/ {s/.*/cgi.fix_pathinfo=0/g}‘ /usr/local/php-$phpVersion/etc/php.ini
sed -i ‘/^expose_php/ {s/.*/expose_php = Off/}‘ /usr/local/php-$phpVersion/etc/php.ini
sed -i ‘/^disable_functions/ {s/.*/disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,exec,passthru,shell_exec,system,proc_open,popen,show_source,phpinfo/g}‘ /usr/local/php-$phpVersion/etc/php.ini
#cp /usr/local/php-$phpVersion/etc/php-fpm.conf.default /usr/local/php-$phpVersion/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cd /usr/local
ln -s php-$phpVersion php
cd /usr/local/php/etc/
cat >/usr/local/php/etc/php-fpm.conf <<EOF
[global]
pid = /var/run/php-fpm.pid
error_log = /var/log/php/php-fpm.error.log 
 
[www]
listen = 127.0.0.1:9000
user = www
group = www
pm = static
pm.status_path = /status
pm.max_children = 50
pm.max_requests = 5000
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 60
request_terminate_timeout = 10s
request_slowlog_timeout = 9s
slowlog = /var/log/php/php-fpm.slow.log
EOF
}

function exten_redis {
cd /usr/local/src
[ ! -f redis-2.2.7.tgz ] && wget https://pecl.php.net/get/redis-2.2.7.tgz
tar xf redis-2.2.7.tgz
cd redis-2.2.7
/usr/local/php/bin/phpize
if [ $? -eq 0 ];then
        ./configure --with-php-config=/usr/local/php/bin/php-config
        [ $? -eq 0 ] && make && make install
        [ $? -eq 0 ] && sed -i "/extension_dir = \"\.\/\"/ a\extension = redis.so" /usr/local/php/etc/php.ini
fi
}

function exten_mongo {
cd /usr/local/src
[ ! -f mongo-php-driver-legacy-1.6.11.tar.gz ] && wget https://github.com/mongodb/mongo-php-driver-legacy/archive/1.6.11.tar.gz -O mongo-php-driver-legacy-1.6.11.tar.gz
tar xf mongo-php-driver-legacy-1.6.11.tar.gz
cd mongo-php-driver-legacy-1.6.11
/usr/local/php/bin/phpize
if [ $? -eq 0 ];then
        ./configure --with-php-config=/usr/local/php/bin/php-config
        [ $? -eq 0 ] && make && make install
        [ $? -eq 0 ] && sed -i "/extension_dir = \"\.\/\"/ a\extension = mongo.so" /usr/local/php/etc/php.ini
fi
}
install_php
[ $retval -ne 0 ] && echo -e "\033[41,30m install php failed,pls check!!! \033[0m";exit 5
config_php
exten_redis
exten_mongo

本文出自 “11414123” 博客,转载请与作者联系!

php编译安装脚本

标签:php编译安装脚本

原文地址:http://11424123.blog.51cto.com/11414123/1845701

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!