Depending on your time zone, PHP 7 was finally released on 3rd/4th of December 2015. Even though the general recommendation for production servers is to wait for a little bit and gather some experiences before upgrading, some of us want to jump right on and upgrade to PHP 7.
Thanks to Ondřej Surý and the PPAs he is maintaining for us, my experience with upgrading from PHP 5 to PHP 7 was quite smooth. It’s not difficult at all, but you need to stay focused in a couple of places.
First of all, add the new repository for PHP 7:
$ apt-get install software-properties-common
$ add-apt-repository ppa:ondrej/php
In the next command, we’ll remove PHP 5 from your system and install PHP 7. You might want to keep a backup of your config files for reference.
$ apt-get update && apt-get purge php5-fpm && apt-get --purge autoremove && apt-get install php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-json php7.0-mcrypt php7.0-opcache php7.0-xml
At this point, php5-fpm should be gone, and the php7.0-fpm service is running. It is, however, unlikely that your website is running properly – because the PHP-FPM socket file will have changed. If you’re running Nginx, you must update your fastcgi_pass directive to this:
And restart Nginx:
$ service nginx restart
You most likely will want to edit the PHP-FPM pool file found in
My Nginx instance runs as the user/group
nginx, so I need to change the following directives:
listen.owner = nginx
listen.group = nginx
$ grep "^user" /etc/nginx/nginx.conf to find your value here)
There is also a good chance you might want to change the
group directives at the beginning of the file. However, I’m fine with them beeing set to
www-data, because I use strict file ownership for WordPress.
After modifying the pool file, remember to restart the PHP-FPM process:
$ service php7.0-fpm restart