bash script to switch PHP versions in Plesk command line

I found myself needing to switch between PHP versions on the command line running under the Plesk environment on a CentOS server. Some apps ran under PHP 5.6, some under 7.0 and others being pushed towards 7.1. This script allows me to be quickly switch between them. It looks for the current PHP version in the PATH and changes just that.

My shell scripting is a little rusty, so you may have some improvements. It shows the PATH before and after, so you should be able to spot if it breaks things, and quickly fix it.

2 Responses to bash script to switch PHP versions in Plesk command line

  1. KooTjoo 2017-10-27 at 14:52 #

    Hi Jason,

    This would be a real time saver but can’t get it to work on my Plesk Onyx setup. If I run the script by using for instance

    setphp 7.0 I get this as output and php version for shel hasn’t changed.:

    /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
    /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

    Anny suugestions?

    Thanks
    KooTjoo

    • Jason Judge 2017-10-27 at 15:08 #

      It looks like the setphp script is not in your path. If it is in the local directory, try running it like this:

      . ./setphp 7.0

      Do you have PHP versions in /opt/plesk/php/ ?

Leave a Reply