首页 互联前沿 Web在线 浏览内容

PHP7.0正式版编译安装升级

2660 0 BaiDu已收录 评论留言

官方给出的新特性如下:

PHP 7.0.0 comes with new version of the Zend Engine with features such as (incomplete list):Improved performance: PHP 7 is up to twice as fast as PHP 5.6Consistent 64-bit supportMany fatal errors are now ExceptionsRemoval of old and unsupported SAPIs and extensionsThe null coalescing operator (??)Combined comparison Operator (< =>)Return Type DeclarationsScalar Type DeclarationsAnonymous Classes

至于新特性是什么,网上都有大牛给出很详细的解释,大致意思如下:

Improved performance: PHP 7 is up to twice as fast as PHP 5.6PHP7的性能将是PHP5.6的2倍!

好了,其他就不用看了,单这一条就已经有升级的动力了吧!


一、编译安装

以下安装步骤是在已有PHP5的环境下进行的,不保证能够顺利完成,仅供参考。
①、下载PHP

cd /usr/local/src#下载安装包wget http://cn2.php.net/distributions/php-7.0.0.tar.gz

这是PHP官方的PHP7.0正式版的国内CDN下载地址,可以放心下载。

一键安装php7
执行命令

wget http://soft.vpser.net/lnmp/upgrade_php.sh;/bin/bash upgrade_php.sh

之后提示输入php版本,,我要升级php7的版本输入

7.0.0

现在只有坐等安装就好了,安装需要点时间。。。。

②、解压编译
基本大家伙都已经安装了PHP的5.6或更老的版本,所以我们可以编译安装到一个新的路径。

#进入安装目录cd php-7.0.0#编译安装#因为是在已经有PHP5.6的环境下安装,下面的参数基本不会报错,如果报错,那么缺少什么就补什么吧!CFLAGS= CXXFLAGS= ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc \--with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache \--disable-fileinfo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-jpeg-dir \--with-iconv-dir=/usr/local --with-freetype-dir --with-png-dir --with-zlib --disable-rpath \--with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-exif --with-curl \--enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-inline-optimization \--enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl \--with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp \--with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug#继续makemake ZEND_EXTRA_LIBS='-liconv'#最后make install完成安装make install

上面的编译安装激活了opcache缓存,如果不需要可以去掉 --enable-opcache,推荐使用。

③、设置参数

#以下操作均在php-7.0.0这个安装目录下执行

php_install_dir=/usr/local/php7cp php.ini-production $php_install_dir/etc/php.iniMem=`free -m | awk '/Mem:/{print $2}'`if [ $Mem -gt 1024 -a $Mem -le 1500 ];then Memory_limit=192elif [ $Mem -gt 1500 -a $Mem -le 3500 ];then Memory_limit=256elif [ $Mem -gt 3500 -a $Mem -le 4500 ];then Memory_limit=320elif [ $Mem -gt 4500 ];then Memory_limit=448else Memory_limit=128fised -i "s@^memory_limit.*@memory_limit = ${Memory_limit}M@" $php_install_dir/etc/php.inised -i 's@^output_buffering =@output_buffering = On\noutput_buffering =@' $php_install_dir/etc/php.inised -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=0@' $php_install_dir/etc/php.inised -i 's@^short_open_tag = Off@short_open_tag = On@' $php_install_dir/etc/php.inised -i 's@^expose_php = On@expose_php = Off@' $php_install_dir/etc/php.inised -i 's@^request_order.*@request_order = "CGP"@' $php_install_dir/etc/php.inised -i 's@^;date.timezone.*@date.timezone = Asia/Shanghai@' $php_install_dir/etc/php.inised -i 's@^post_max_size.*@post_max_size = 50M@' $php_install_dir/etc/php.inised -i 's@^upload_max_filesize.*@upload_max_filesize = 50M@' $php_install_dir/etc/php.inised -i 's@^;upload_tmp_dir.*@upload_tmp_dir = /tmp@' $php_install_dir/etc/php.inised -i 's@^max_execution_time.*@max_execution_time = 600@' $php_install_dir/etc/php.inised -i 's@^;realpath_cache_size.*@realpath_cache_size = 2M@' $php_install_dir/etc/php.inised -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' $php_install_dir/etc/php.inised -i 's@^session.cookie_httponly.*@session.cookie_httponly = 1@' $php_install_dir/etc/php.inised -i 's@^mysqlnd.collect_memory_statistics.*@mysqlnd.collect_memory_statistics = On@' $php_install_dir/etc/php.ini[ -e /usr/sbin/sendmail ] && sed -i 's@^;sendmail_path.*@sendmail_path = /usr/sbin/sendmail -t -i@' $php_install_dir/etc/php.ini#如果编译时去掉了 --enable-opcache,则以下包含opcache的都请忽略sed -i 's@^\[opcache\]@[opcache]\nzend_extension=opcache.so@' $php_install_dir/etc/php.inised -i 's@^;opcache.enable=.*@opcache.enable=1@' $php_install_dir/etc/php.inised -i "s@^;opcache.memory_consumption.*@opcache.memory_consumption=$Memory_limit@" $php_install_dir/etc/php.inised -i 's@^;opcache.interned_strings_buffer.*@opcache.interned_strings_buffer=8@' $php_install_dir/etc/php.inised -i 's@^;opcache.max_accelerated_files.*@opcache.max_accelerated_files=4000@' $php_install_dir/etc/php.inised -i 's@^;opcache.revalidate_freq.*@opcache.revalidate_freq=60@' $php_install_dir/etc/php.inised -i 's@^;opcache.save_comments.*@opcache.save_comments=0@' $php_install_dir/etc/php.inised -i 's@^;opcache.fast_shutdown.*@opcache.fast_shutdown=1@' $php_install_dir/etc/php.inised -i 's@^;opcache.validate_timestamps.*@opcache.validate_timestamps=1@' $php_install_dir/etc/php.inised -i 's@^;opcache.enable_cli.*@opcache.enable_cli=1@' $php_install_dir/etc/php.inised -i 's@^;opcache.use_cwd.*@opcache.use_cwd=1@' $php_install_dir/etc/php.inised -i 's@^opcache.max_accelerated_files.*@opcache.max_accelerated_files=100000@' $php_install_dir/etc/php.inised -i 's@^;opcache.max_wasted_percentage.*@opcache.max_wasted_percentage=5@' $php_install_dir/etc/php.inised -i 's@^;opcache.consistency_checks.*@opcache.consistency_checks=0@' $php_install_dir/etc/php.inised -i 's@^;opcache.optimization_level.*@;opcache.optimization_level=0@' $php_install_dir/etc/php.ini# php-fpm直接沿用之前的配置即可cp -f /usr/local/php/etc/php-fpm.conf /usr/local/php7/etc/

Ps:以上参数等代码从lnmp一键安装包中提取。

④、版本替换
php 7 已经安装到了 /usr/local/php7,为了让2个版本暂时都存在,方便过渡,这里我们使用软链接搞定

#停止php-fpmservice php-fpm stop#重命名php老版本cd /usr/localmv /php php5#建立php7的软链接ln -s php7 php#启动php-fpmservice php-fpm start

做完以上步骤,要是没报错基本就已经搞定了,执行一下php --version 应该可以看到版本信息了

PHP 7.0.0 (cli) (built: Dec 2 2015 19:44:28) ( NTS )Copyright (c) 1997-2015 The PHP GroupZend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

注:如遇PHP安装报错,参考以下
安装最后发现有问题,提示截图的错误:

php7-cw

php7-cw


这是因为这个模块要个php版本配套,官网显示最新版本只支持到php5.6
zend-php5.6

zend-php5.6


没有php7的版本只能把这个模块去掉,php.ini中注释这个模块
Zend Guard Loader是一个php的加速模块所以去除没有什么关系
在重启一下php

service php-fpm restart

重启php

restart-php

restart-php


没有错误提示,于是去查一下wordpress跑起来还有什么问题
本站还在测试PHP7.0版本,暂时不公布其它方法
使用Wordpress小伙伴可参考:https://zhangge.net/5075.html

标签:
墨月的头像
  • 本文由墨月网络整理编辑,转载请以链接形式注明本文地址:https://www.moyoo.net/12567.html
    版权所有© 墨月网络 | 本文采用 BY-NC-SA 进行授权丨发布于:2015-12-06 15:28
    若未注明,均为原创;部分内容源于网络,版权归原作者所有,如有侵权,请联系我们删除。
已有 0 条评论 新浪微博

关注我们,实时联系

AD

AD