How to upgrade to PHP 7 on Ubuntu

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:

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.

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:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
And restart Nginx: $ service nginx restart

You most likely will want to edit the PHP-FPM pool file found in /etc/php/7.0/fpm/pool.d/www.conf:

My Nginx instance runs as the user/group nginx, so I need to change the following directives:

(run $ grep "^user" /etc/nginx/nginx.conf to find your value here)

There is also a good chance you might want to change the user and 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:

There are 36 comments

I love comments that bring new insights, shares ideas and experiences, and most of all: corrects my mistakes. For support questions, there are other fora, like Stack Overflow, Server Fault and the WordPress support forum.

Your email address will not be published. Required fields are marked *