David Lohmeyer's Blog

Telling Ubuntu 16 to use a different PHP version on cli

When you have multiple versions of PHP installed things can get a bit wonky. PHP 7.1 has broken a lot, and I've noticed most LAMP apps and a lot of commandline tools such as Drush just aren't compatible yet.

With Nginx, it makes it easy to run your sites on a specific PHP version like 7.0, but if you install 7.1 on your server you might want cli applications to use 7.0 still.

In Ubuntu, if you use "which php" you can see that PHP points to /usr/bin/php. You'll also find that /usr/bin/php is a symlink to /etc/alternatives/php. /etc/alternatives/php is in turn a symlink to something like /usr/bin/php7.1! Confused yet?

While inside the /etc/alternatives folder:

sudo rm php
sudo ln -s /usr/bin/php7.0 php

This will unlink something like PHP 7.1 and remake the symlink to PHP 7.0 for commandline applications.

Related Posts