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.
What are your thoughts on "Upgrading PHP 5.6 to 7.0 on a Forge provisioned server"?