Centos6.X安装php7

1、去官网下载镜像文件: http://php.net/get/php-7.2.3.tar.gz/from/a/mirror

      找香港的下载: 

 2、  cd /usr/local/src   所有的软件源码放到这里

    wget http://hk1.php.net/get/php-7.2.3.tar.gz/from/this/mirror

    mv  mirror  php-7.2.3

    cd php-7.2.3

3、开始编译:

# ./configure --prefix=/usr/local/php7 \

 --with-curl \

 --with-freetype-dir \

 --with-gd \

 --with-gettext \

 --with-iconv-dir \

 --with-kerberos \

 --with-libdir=lib64 \

 --with-libxml-dir \

 --with-mysqli \

 --with-openssl \

 --with-pcre-regex \

 --with-pdo-mysql \

 --with-pdo-sqlite \

 --with-pear \

 --with-png-dir \

 --with-xmlrpc \

 --with-xsl \

 --with-zlib \

 --enable-fpm \

 --enable-bcmath \

 --enable-libxml \

 --enable-inline-optimization \

 --enable-gd-native-ttf \

 --enable-mbregex \

 --enable-mbstring \

 --enable-opcache \

 --enable-pcntl \

 --enable-shmop \

 --enable-soap \

 --enable-sockets \

 --enable-sysvsem \

 --enable-xml \

 --enable-zip

由于我原本安装好了相关库,所以我不需要再安装了,如果安装报错,就yum下。

如果配置错误,需要安装需要的模块,直接yum一并安装依赖库

# yum -y install libjpeg libjpeg-devel libpng libpng-devel \

 freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel

网上很多所谓的教程都是直接:

4、# make &&  make install

但是这样可能会报错:make: *** [sapi/cli/php] error 1

其实这样就行了:

make ZEND_EXTRA_LIBS='-liconv'

make install

5、然后搞些配置吧

# cp php.ini-production /usr/local/php7/etc/php.ini

# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm7

6、开机自启动:

     cd /etc/init.d 

     vim php7-fpm

     内容如下:

#! /bin/sh

#chkconfig: 2345 10 90

## vim /usr/local/php7/etc/php-fpm.conf  #uncomment pid under [global]  #pid = run/php-fpm.pid

## vim /etc/init.d/php7-fpm

## chmod a+x /etc/init.d/php7-fpm

## chkconfig --add php7-fpm

## chkconfig php7-fpm on

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="php-fpm7 daemon"

NAME=php-fpm

INSTALLDIR=/usr/local/php7

DAEMON=$INSTALLDIR/sbin/$NAME

CONFIGFILE=$INSTALLDIR/lib/$NAME.conf

PIDFILE=$INSTALLDIR/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/php-fpm72

set -e

[ -x "$DAEMON" ] || exit 0

do_start() {

    $DAEMON -D || echo -n "php-fpm7 already running"

}

do_stop() {

    kill -INT `cat $PIDFILE` || echo -n "php-fpm7 not running"

}

do_test() {

    $DAEMON -t || echo -n "php-fpm7 can't test"

}

case "$1" in

    start)

        echo -n "Starting $DESC: $NAME"

        do_start

        echo "."

    ;;

    stop)

        echo -n "Stopping $DESC: $NAME"

        do_stop

        echo "."

    ;;

    restart)

        echo -n "Restarting $DESC: $NAME"

        do_stop

        do_start

        echo "."

    ;;

    test)

        echo -n "Testing $DESC: $NAME"

        do_test

        echo "."

    ;;

    *)

    echo "Usage: $SCRIPTNAME {start|stop|restart|test}" >&2

    exit 3

    ;;

esac

exit 0

7、chmod a+x /etc/init.d/php7-fpm

     chkconfig --add php7-fpm

      chkconfig php7-fpm on

8、service php7-fpm start 


到此安装完毕

9、检查ini位置

      php --ini

      [root@localhost init.d]# php --ini

      Configuration File (php.ini) Path: /usr/local/php7/lib

      Loaded Configuration File:        /usr/local/php7/lib/php.ini

      Scan for additional .ini files in: (none)

      Additional .ini files parsed:      (none)

      You have new mail in /var/spool/mail/root

10、所有的扩展路径:/usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/

11、php7.2 如果pecl install *** 不成功的话 可以通过源码phpize 安装 记得ini别错了 

你可能感兴趣的:(Centos6.X安装php7)