Centos安装php(含php-fpm)

  1. 准备编译环境

    yum -y install gcc automake autoconf libtool make gcc-c++ glibc
    
  2. 安装php依赖项

    yum -y install libxslt-devel 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-devel libidn libidn-devel openssl openssl-devel
    
  3. 下载php安装包

    cd /home/soft
    wget -O php-5.6.14.tar.gz http://cn2.php.net/get/php-5.6.14.tar.gz/from/this/mirror
    
  4. 解压php安装包

    tar zxvf php-5.6.14.tar.gz
    
  5. 安装php

    cd php-5.6.14
    ./configure --enable-fpm \--enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath \--enable-inline-ptimization --with-bz2  --with-zlib --enable-sockets \--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \--enable-zip --with-pcre-regex --with-mysql --with-mysqli \--with-gd --with-jpeg-dir
    出现Thank for You using PHP字样说明php配置成功。       
    make && make install 安装php
    
  6. 安装成功之后创建用户和用户组

    创建用户组:groupadd user-php
    创建用户:useradd -g user-php user-php
    
  7. 配置php-fpm

    cd /use/local/etc
    cp php-fpm.conf.default php-fpm.conf
    vim php-fpm.conf
    修改(149行):
    user = user-php;
    group = user-php;
    修改(164行),配置所有IP都可链接使用php-fpm;
    listen = [::]:9000;
    
  8. 讲php-fpm配置成service

    修改php-fpm.conf文件,设置pid文件存放路径:
    pid = /var/run/php-fpm.pid
    创建服务脚本:
    vim /etc/init.d/php-fpm
    写入php-fpm服务脚本代码。
    设置服务脚本的执行权限
    chmod +x /etc/init.d/php-fpm
    设置php-fpm服务开机自启动
    chkconfig php-fpm on
    
#! /bin/sh

### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO

prefix=/usr
exec_prefix=/usr

php_fpm_BIN=/usr/local/sbin/php-fpm
php_fpm_CONF=/usr/local/etc/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid


php_opts="--fpm-config $php_fpm_CONF"


wait_for_pid () {
        try=0

        while test $try -lt 35 ; do

                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;

                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                esac

                echo -n .
                try=`expr $try + 1`
                sleep 1

        done

}


case "$1" in
        start)
                echo -n "Starting php-fpm "

                $php_fpm_BIN $php_opts

                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi

                wait_for_pid created $php_fpm_PID

                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;

        stop)
                echo -n "Gracefully shutting down php-fpm "

                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi

                kill -QUIT `cat $php_fpm_PID`

                wait_for_pid removed $php_fpm_PID

                if [ -n "$try" ] ; then
                        echo " failed. Use force-quit"
                        exit 1
                else
                        echo " done"
                fi
        ;;

        force-quit)
                echo -n "Terminating php-fpm "

                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi

                kill -TERM `cat $php_fpm_PID`

                wait_for_pid removed $php_fpm_PID

                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;

        restart)
                $0 stop
                $0 start
        ;;

        reload)

                echo -n "Reload service php-fpm "

                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi

                kill -USR2 `cat $php_fpm_PID`

                echo " done"
        ;;

        *)
                echo "Usage: $0 {start|stop|force-quit|restart|reload}"
                exit 1
        ;;

esac

本文参考相关链接:http://www.cnblogs.com/ppoo24/p/4920106.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值