PHP7性能大幅提升,为了更好的运行wordpress,我的网站也升级到了7,下面是当时的参考文档,步骤很简单。
How to install PHP 7 (stable) on VestaCP server running on CentOS 7 with some test results of how VestaCP + PHP 7 can perform together serving WordPress site. For your information, PHP 7 has just been released and many rumors say it can perform multiple times faster than previous stable PHP version and also as fast as HHVM. This is the most anticipated PHP version ever bringing many new features, enhancements, and improved performance.
Until the time I write this post, VestaCP is by default using PHP 5.4.x installed and running with web server (either Apache or Nginx). I’m not really sure why its developer still pack PHP 5.4 within VestaCP installation but as far as I know PHP 5.4 is the most popular stable version after 5.3 that many scripts, web apps and CMS are supported (can still run well with the PHP environment).
As per PHP 7, there are still not enough information of how many CMS / scripts except WordPress and OwnCloud those are already PHP 7 compatible. So if you are planning to build a WordPress site with VestaCP, you can try this tutorial and feel the awesomeness of PHP 7. But I must also remind you that since VestaCP doesn’t include PHP 7 by default yet, so I recommend you to not using VestaCP + PHP 7 on production websites unless you are a sysadmin Ninja. However, with default Vesta setup (Nginx as proxy + Apache + PHP), this method still can work properly so it is safe if you’ll just want to host personal blog or few blogs inside one server.
安装前需要一些什么
- 需要SSH权限,以及SSH客户端 or Putty and basic knowledge about how to use it.
- 基本的指令会使用 Basic knowledge about common Unix command to SSH to your server.
- 一台VPS最好有1G以上的内存,2G的更好.
- 确信你的VestaCP 服务器已安装并运行在centos系统下。.
- 有30分钟空余时间(完全不需要,10分钟就搞定了)。
- 一杯饮料(哈哈).
Confused on choosing which VPS provider to install VestaCP? Read my recommended VPS providers or top low end cloud server providers. Quick recommendation: Digital Ocean, Atlantic.net or Ramnode.
如何安装 How to Install
p.s: Please click any image you wish to see its larger version.
Step 1 – Install VestaCP on your vps, cloud or dedicated server. You can follow the step by step tutorial posted previously. Despite this tutorial done on CentOS 7, but the steps are pretty much similar. 安装VestaCp到你的服务器上,这里尝试的是centos7,我的服务器是centos6的,也没问题。
Step 2 – Once installed, still in Putty, you can do initial check of what PHP version is installed: 安装完毕后查看一下安装的版本,如果是7就别升了,哈哈。
# php -VPHP 5.4.45 (cli) (built: Jul 22 2016 19:13:31)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
it should look like this (PHP 5.4.45):
Step 3 – Now we need to install remi repo or at least make it updated. PHP 7 is considered new and is not available via Yum at base CentOS repo.现在需要下载最新版的remi 与epel。
我的版本是centos6,所以指令是:
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
centos7的指令如下:
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
Step 4 – Now issue this command to update and enable it 现在update一下系统
yum --enablerepo=remi update remi-release
Step 5 – Now delete current PHP installation but make sure you stopped Apache first: 停止httpd以及删除原来的php版本
备份一下依赖于php的roundmail,虽然phpMyAdmin没有影响,我还是备份了
cd /etc/httpd/conf.d/ mv roundcubemail.conf roundcubemail.conf.bak mv phpMyAdmin.conf phpMyAdmin.conf.bak cd /etc/ mv phpMyAdmin/ phpMyAdminbak/ mv roundcubemail/ roundcubemailbak/ cd /usr/share/ mv phpMyAdmin/ phpMyAdminbak/ mv roundcubemail/ roundcubemailbak/ ll
service httpd stop yum -y remove php
Step 6 – Finally, issue this command to install PHP 7.0 with all necessary modules: 现在开始安装php7.o,貌似命令有点长啊
yum --enablerepo=remi-php70 install php70-php php70-php-pear php70-php-bcmath php70-php-pecl-jsond-devel php70-php-mysqlnd php70-php-gd php70-php-common php70-php-fpm php70-php-intl php70-php-cli php70-php php70-php-xml php70-php-opcache php70-php-pecl-apcu php70-php-pecl-jsond php70-php-pdo php70-php-gmp php70-php-process php70-php-pecl-imagick php70-php-devel php70-php-mbstring php70-php-pecl-zip php70-php-snmp -y
安装完之后恢复一下备份文件cd /etc/httpd/conf.d/ mv roundcubemail.conf.bak roundcubemail.conf mv phpMyAdmin.conf.bak phpMyAdmin.conf cd /etc/ mv phpMyAdminbak/ phpMyAdmin/ mv roundcubemailbak/ roundcubemail/ cd /usr/share/ mv phpMyAdminbak/ phpMyAdmin/ mv roundcubemailbak/ roundcubemail/ ll
service php-fpm stop service php70-php-fpm start
# service php-fpm stop
php-fpm: unrecognized service
Step 8 – Finally you can delete the old php symblink and create a new one: 更改php的软连接
rm /usr/bin/php ln -s /usr/bin/php70 /usr/bin/php
service httpd restart
php -v
# php -v
PHP 7.0.11 (cli) (built: Sep 14 2016 07:27:30) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.11, Copyright (c) 1999-2016, by Zend Technologies
大功告成!
ps:原文中未加入zip模块,我的owncloud安装后报错,所以需要增加php70-php-pecl-zip安装,已加在安装文件指令中了。