Page 1 of 1

HOWTO: Enable PHP7 (with OPCache) on Debian (Ubuntu)

Posted: Tue Nov 08, 2016 12:46 pm
by PagesAtHome
So you want this too huh:
Image


NB for those doubting the use of enabling OPCache, check this benchmark ->
Image
(do note that HHVM and PHP7 both have their advantages when comparing either transactions or queries per second)


Then lets get to business ->>


1. Use the dotdeb repository:
(the dotdeb variant is compiled and configured for use with OPCache, so it's HIGHLY recommended to use this repo)

To add the dotdeb repository, from https://www.dotdeb.org/instructions/ (although you might also use another repo for Ubuntu)


Edit /etc/apt/sources.list and add

Code: Select all

deb http://packages.dotdeb.org jessie all
(echoing the line into the file didnt seem to work for me, so i had to edit it in manually)


Fetch the repository key and install it.

Code: Select all

wget https://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg

Do then

Code: Select all

sudo apt-get update






2. Upgrade to or install PHP 7.0

Code: Select all

sudo apt-get install php7.0 php7.0-xml php7.0-zip php7.0-mysql libapache2-mod-php7.0 -y





3. Make PHP 7 the standard version:

check

Code: Select all

php --version

if it shows your old version (it probably will), then first, disable the php5 module:

Code: Select all

a2dismod php5

then, enable the php7 module:

Code: Select all

a2enmod php7.0

Next, reload/restart the Apache service:

Code: Select all

service apache2 restart




4. Check your running software


Check the active PHP version now:

Code: Select all

php --version
it should say something like
PHP 7.0.13-1~dotdeb+8.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.13-1~dotdeb+8.1, Copyright (c) 1999-2016, by Zend Technologies


Also check the OPCache status:
Keep in mind that PHP has separate config files for apache, phpfpm and the cli (command line version) under its /etc/php/7.0/ directory, so the above command only reflects the settings of the /cli file, which in the beginning are the same for all folders. You are free to edit these files as needed, or maybe better; symlinking them all to one 'base php.ini'.

To check your webversion:
create a info.php file with the following content and put it in one of your domain folders, next access this file with a web browser and start searching for entries with 'opcache'.

Code: Select all

<?php
phpinfo();
?>

To check your cli version:

Code: Select all

php -i | grep opcache
Somewhere it should say 'opcache.enable => on => on'







5. Check your applications



Good luck!







sources:
For PHP7
viewtopic.php?p=49243#p49240
http://unix.stackexchange.com/questions ... -on-jessie
http://stackoverflow.com/questions/3598 ... -in-apache
http://stackoverflow.com/questions/3605 ... -not-exist
https://www.digitalocean.com/community/ ... -wordpress

For OPCache
https://www.keycdn.com/blog/php-7-vs-hhvm
http://php.net/manual/en/opcache.installation.php
http://askubuntu.com/questions/490158/h ... untu-14-04
http://stackoverflow.com/questions/2277 ... he-running


NB also check out my HTTP2/SSL tutorial viewtopic.php?t=13150