将Ubuntu16.04的PHP升级到7.1并更新扩展

     0评论

最近试运行一些项目,频频遇到要求PHP7.1的情形,多是由于doctrine这个依赖导致的,于是决定升级PHP到7.1。不过Ubunut16.04的官方repo中,PHP7是7.0版本,本文介绍如何将PHP7升级到7.1,并更新已安装的PHP扩展。

官方repo中只有7.0版本的软件包:

[email protected]:/vagrant/# apt-cache search php7 libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module) php-all-dev - package depending on all supported PHP development packages php7.0 - server-side, HTML-embedded scripting language (metapackage) php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.0-cli - command-line interpreter for the PHP scripting language php7.0-common - documentation, examples and common module for PHP php7.0-curl - CURL module for PHP php7.0-dev - Files for PHP7.0 module development php7.0-gd - GD module for PHP php7.0-gmp - GMP module for PHP php7.0-json - JSON module for PHP php7.0-ldap - LDAP module for PHP php7.0-mysql - MySQL module for PHP php7.0-odbc - ODBC module for PHP php7.0-opcache - Zend OpCache module for PHP php7.0-pgsql - PostgreSQL module for PHP php7.0-pspell - pspell module for PHP php7.0-readline - readline module for PHP php7.0-recode - recode module for PHP php7.0-snmp - SNMP module for PHP php7.0-sqlite3 - SQLite3 module for PHP php7.0-tidy - tidy module for PHP php7.0-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.0-xmlrpc - XMLRPC-EPI module for PHP libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library) php7.0-bcmath - Bcmath module for PHP php7.0-bz2 - bzip2 module for PHP php7.0-enchant - Enchant module for PHP php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary) php7.0-imap - IMAP module for PHP php7.0-interbase - Interbase module for PHP php7.0-intl - Internationalisation module for PHP php7.0-mbstring - MBSTRING module for PHP php7.0-mcrypt - libmcrypt module for PHP php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary) php7.0-soap - SOAP module for PHP php7.0-sybase - Sybase module for PHP php7.0-xsl - XSL module for PHP (dummy) php7.0-zip - Zip module for PHP php7.0-dba - DBA module for PHP php7.2-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.2-common - documentation, examples and common module for PHP

首先添加PPA软件源:

apt-get install software-properties-common add-apt-repository ppa:ondrej/php

然后更新:

sudo apt-get update sudo apt-get upgrade

这次操作是在本地的vagrant上运行的,拉取软件包太慢,于是Ctrl-C后设置代理:

export https_proxy=http://192.168.99.1:1080 export http_proxy=http://192.168.99.1:1080

重新运行更新命令,一会儿就安装好了。看得出PHP 5.6也被更新了。

[email protected]:/vagrant/# apt-get upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages have been kept back: libgd3 libpcre16-3 libpcre3 libpcre3-dev libpcre32-3 php-cli php-curl php-mbstring php-mysql The following packages will be upgraded: dh-php libapache2-mod-php5.6 libapache2-mod-php7.0 libjbig0 libssl-dev libssl-doc libssl1.1 libxml2 libxml2-dev libyajl-dev libyajl2 openssl php-common php-pear php-xml php5.6 php5.6-cli php5.6-common php5.6-dev php5.6-json php5.6-mbstring php5.6-mysql php5.6-opcache php5.6-readline php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-json php7.0-mbstring php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml php7.2-common php7.2-xml pkg-php-tools 37 upgraded, 0 newly installed, 0 to remove and 9 not upgraded. Need to get 17.8 MB/19.3 MB of archives. After this operation, 2,324 kB of additional disk space will be used. Do you want to continue? [Y/n] y

然后看看之前安装的对应PHP7.0的扩展都有哪些:

[email protected]:/vagrant/# dpkg -l | grep php7 | awk '{print $2}' libapache2-mod-php7.0 php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-json php7.0-mbstring php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml php7.2-common php7.2-xml

针对7.0的软件包,安装相应的7.1版本:

apt install libapache2-mod-php7.1 php7.1-cli php7.1-common php7.1-curl php7.1-gd php7.1-json php7.1-mbstring php7.1-mysql php7.1-opcache php7.1-readline php7.1-xml -y

运行完之后重新查看php7开头的软件包,已经满足需求了:

[email protected]:/vagrant/# dpkg -l | grep php7 | awk '{print $2}' libapache2-mod-php7.0 libapache2-mod-php7.1 php7.0-cli php7.0-common php7.0-curl php7.0-gd php7.0-json php7.0-mbstring php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml php7.1-cli php7.1-common php7.1-curl php7.1-gd php7.1-json php7.1-mbstring php7.1-mysql php7.1-opcache php7.1-readline php7.1-xml php7.2-common php7.2-xml

查看CLI环境下PHP的默认版本:

[email protected]:/vagrant/# php -v PHP 7.1.18-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 11 2018 14:22:30) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.1.18-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

查看apache的PHP模块:

[email protected]:/vagrant/# ls /etc/apache2/mods-available/ | grep php7.1 php7.1.conf php7.1.load

在apache中启用PHP7.1

[email protected]:/vagrant/# a2dismod php7.0 Module php7.0 disabled. To activate the new configuration, you need to run: service apache2 restart [email protected]:/vagrant/# a2enmod php7.1 Considering dependency mpm_prefork for php7.1: Considering conflict mpm_event for mpm_prefork: Considering conflict mpm_worker for mpm_prefork: Module mpm_prefork already enabled Considering conflict php5 for php7.1: Enabling module php7.1. To activate the new configuration, you need to run: service apache2 restart [email protected]:/vagrant/# service apache2 reload

至此升级PHP到7.1的任务完成。

参考资料

-- EOF --

本文最后修改于2年前 (2018-06-19)

差评不太行一般挺好非常不错 (No Ratings Yet)
读取中...
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址