Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

Upgrading PHP 5.6 to 7.0 on a Forge provisioned server

If you’ve read some posts before on this blog, then you’ll probably know that I’m a big fan of Forge. The service makes it very easy to set up and administer servers. At my company we’ve been using it since it launched.

We currently have 80 provisioned servers. Most of them are small droplets. We have a policy of running every site on it’s own droplet. This approach has many benefits, but that’s maybe something for a future post.

The bulk of our servers are on PHP 5.6. That’s not too bad, but once you have some sites on PHP 7, the sites running on those servers feel a bit slow. It’s amazing how fast you get used to the speed that PHP 7 offers. That’s why I experimented a bit with upgrading the PHP version on a Forge provisioned server. My gut feeling was that upgrading the PHP version is less work that setting up a new server and moving a site to it.

To not mess up a live site I created a snapshot and used that to set up a server to toy around with. With a little bit of research I came up with these instructions to upgrade the PHP version.

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.0

sudo apt-get install php7.0-fpm

Depending on your project you will need less or more php extensions, but these were the ones relevant for my site:

sudo apt-get install php7.0-gd

sudo apt-get install php7.0-mysql

sudo apt-get install php-memcached

sudo apt-get install php7.0-mcrypt

sudo apt-get install php-curl

sudo apt-get install php-imagick

Next, in the nginx configuration of the site I replaced unix:/var/run/php5-fpm.sock with unix:/var/run/php/php7.0-fpm.sock

The final adjustment I made was to make sure nginx would spawn the php processes under the forge. This will make sure that a php process can write to sites previously created by Forge:

// in the file /etc/php/7.0/fpm/pool.d/www.conf
user = forge
group = forge

After that I rebooted the server (maybe just restarting nginx is enough) and enjoyed browsing a site that was four times as fast. ?

If you decide to try this out for your server, be aware that what works for me doesn’t necessarily work for you. Every site is a bit different. But I’m sure the instructions from this post will get you pretty far. Happy upgrading!

EDIT: Meanwhile DigitalOcean also published a guide on how to upgrade to PHP 7.

Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band. He loves waffles and butterflies.
  • vesper8

    This may work well if you only have one site on your forge installation. But the idea of having to manually modify the generated nginx files for every site just seems like a bad idea. What if you provision new site using the Forge interface after upgrading to 7.0? Will the provisionner scripts add the correct 7.0 references or will you have to update them manually every time?

  • expediteA

    This is the downside of using forge for me. I only run 1 server and for $10/month i’d want this dealt with automatically. I find any time I want to bump up version it’s easier to recreate the server and transfer. Usually when I try manually I break my sites.

  • Pingback: Enable http2 on a Forge provisioned server - murze.be()

  • Hélio

    Helped a lot

  • The only downside of this is, is that Forge still thinks your server runs php5.6 and there is no way you can change that (as far as I can see) in the Forge UI. I have this issue now after upgrading from 7.0 to 7.1 . Well, it’s not a big deal because I don’t use the UI to change any server config, but it would still be nice.

    For example, try to edit the PHP FPM or PHP CLI config through Forge.

    • hmm, that mean it sill show php version as 5.6 in dashboard ?