需求
服务器 Centos 6.3 上的php版本 5.6.12(如下),现在想升级到 php-7.1.32
php -v
PHP 5.6.12 (cli) (built: Mar 28 2017 23:48:05)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
主要步骤
1.php官网找升级版本源码 http://www.php.net/downloads.php
源码包: wget https://www.php.net/distributions/php-7.1.32.tar.gz --no-check-certificate
2.wget下载 tar解压
tar -xvf php-7.1.32.tar.gz
3.#获取php编译时的参数
php -i | grep Command
Configure Command => './configure' '--prefix=/alidata/server/php-5.6.12' '--exec-prefix=/alidata/server/php-5.6.12' '--bindir=/alidata/server/php-5.6.12/bin' '--sbindir=/alidata/server/php-5.6.12/sbin' '--includedir=/alidata/server/php-5.6.12/include' '--libdir=/alidata/server/php-5.6.12/lib/php' '--mandir=/alidata/server/php-5.6.12/php/man' '--with-config-file-path=/alidata/server/php-5.6.12/etc' '--with-mcrypt=/usr/include' '--with-mhash' '--with-openssl' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-gd' '--with-iconv' '--with-zlib' '--enable-zip' '--enable-inline-optimization' '--disable-debug' '--disable-rpath' '--enable-shared' '--enable-xml' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-mbregex' '--enable-mbstring' '--enable-ftp' '--enable-gd-native-ttf' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-soap' '--without-pear' '--with-gettext' '--enable-session' '--with-curl' '--with-jpeg-dir' '--with-freetype-dir' '--enable-opcache' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--without-gdbm' '--disable-fileinfo' '--with-iconv=/usr/local/libiconv'
Server API => Command Line Interface
Command buffer size => 4096
4.进入解压目录编译安装,使用上面过滤好的参数(注意 php-5.6.12 改成 php-7.1.32)
cd /alidata/softwares/php-7.1.32
# 执行下面命令
./configure '--prefix=/alidata/server/php-7.1.32' '--with-mcrypt=/usr/include' '--with-mhash' '--with-openssl' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-gd' '--with-iconv' '--with-zlib' '--enable-zip' '--enable-inline-optimization' '--disable-debug' '--disable-rpath' '--enable-shared' '--enable-xml' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-mbregex' '--enable-mbstring' '--enable-ftp' '--enable-gd-native-ttf' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-soap' '--without-pear' '--with-gettext' '--enable-session' '--with-curl' '--with-jpeg-dir' '--with-freetype-dir' '--enable-opcache' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--without-gdbm' '--disable-fileinfo' '--with-iconv=/usr/local/libiconv'
# 执行编译安装
make && make install
# 执行成功如下
Installing helper programs: /alidata/server/php-7.1.32/bin/
program: phpize
program: php-config
Installing man pages: /alidata/server/php-7.1.32/php/man/man1/
page: phpize.1
page: php-config.1
/alidata/softwares/php-7.1.32/build/shtool install -c ext/phar/phar.phar /alidata/server/php-7.1.32/bin
ln -s -f phar.phar /alidata/server/php-7.1.32/bin/phar
Installing PDO headers: /alidata/server/php-7.1.32/include/php/ext/pdo/
假如编译报如下错:
INSTALL_IT =
LFLAGS =
LIBTOOL = $(SHELL) $(top_builddir)/libtool --silent --preserve-dup-deps
"Makefile" 1282L, 166778C written
ext/iconv/.libs/iconv.o: In function `php_iconv_string':
/alidata/server/php-7.2.31/ext/iconv/iconv.c:576: undefined reference to `libiconv_open'
/alidata/server/php-7.2.31/ext/iconv/iconv.c:585: undefined reference to `libiconv'
/alidata/server/php-7.2.31/ext/iconv/iconv.c:601: undefined reference to `libiconv'
/alidata/server/php-7.2.31/ext/iconv/iconv.c:611: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o: In function `_php_iconv_strpos':
/alidata/server/php-7.2.31/ext/iconv/iconv.c:995: undefined reference to `libiconv_open'
/alidata/server/php-7.2.31/ext/iconv/iconv.c:1023: undefined reference to `libiconv'
/alidata/server/php-7.2.31/ext/iconv/iconv.c:1137: undefined reference to `libiconv_close'
ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_append_bucket':
/alidata/server/php-7.2.31/ext/iconv/iconv.c:2652: undefined reference to `libiconv'
/alidata/server/php-7.2.31/ext/iconv/iconv.c:2725: undefined reference to `libiconv'
/alidata/server/php-7.2.31/ext/iconv/iconv.c:2724: undefined reference to `libiconv'
ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':
/alidata/server/php-7.2.31/ext/iconv/iconv.c:2608: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
解决方案:在执行完 ./configure ... 之后,修改下 Makefile,找到 EXTRA_LIBS,在后面添加 -liconv
image.png
然后继续执行 make & make install
5.进入php源码目录,选择php.ini-development复制一份到--prefix参数路径下的lib下(如:/usr/local/php/lib/php.ini),并改名为php.ini
6.若找不到扩展库,编辑php.ini,查找extension_dir,修改为extension_dir = "/alidata/server/php-7.1.32/lib/php/extensions",目的是找到和php.ini同目录下的ext文件夹中的扩展库。
7.配置php.ini常用项(upload_max_filesize=8M,date.timezone = PRC,short_open_tag = On)
8.配置php-fpm
[root@iZ2 php-fpm.d]# pwd
/alidata/server/php/etc/php-fpm.d
[root@iZ2 php-fpm.d]# ls
www.conf www.conf.default
[root@iZ2 etc]# pwd
/alidata/server/php/etc
[root@iZ2 etc]# ls
php-fpm.conf php-fpm.conf.default php-fpm.d
8.配置service
[root@iZ2 init.d]# pwd
/etc/init.d
cp -rf /alidata/softwares/php-7.1.32/sapi/fpm/init.d.php-fpm php-fpm
service php-fpm restart
init.d.php-fpm 配置如下
#! /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=/alidata/server/php-7.1.32
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
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 --daemonize $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
;;
status)
if [ ! -r $php_fpm_PID ] ; then
echo "php-fpm is stopped"
exit 0
fi
PID=`cat $php_fpm_PID`
if ps -p $PID | grep -q $PID; then
echo "php-fpm (pid $PID) is running..."
else
echo "php-fpm dead but pid file exists"
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"
;;
configtest)
$php_fpm_BIN -t
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
exit 1
;;
esac
网友评论