Every webdeveloper needs to swith PHP version on his/her development setup. While you can do that manually every single time by using sudo a2dismod and sudo a2enmod and then restarting your server, it’s much easier and faster to write a quick bash script to do that for you.
Swith PHP version on the terminal
When working with the terminal, I am used to having shortcurts set up to make my work a bit faster an a bit more fun.
That is why I have written this tiny bash script to let me change my PHP version right from the terminal without having to disable and enable the PHP versions and then restart the server manually.
Feel free to just copy and paste it and place it as an executable in your /usr/bin or just /bin directory on your server.
#!/bin/sh if ["$1" = ""] then echo "Enter a PHP version - either 5.6 or 7 at the moment"; exit; fi echo "Switching PHP version to $1"; if [ "$1" = "5.6" ] then sudo a2dismod php7.0 sudo a2enmod php5.6 sudo service apache2 restart elif [ "$1" = "7" ] then sudo a2dismod php5.6 sudo a2enmod php7.0 sudo service apache2 restart fi
I call this file switchphp , and it resides in my /bin directory.
So copy the script above, save it to your /bin/switchphp file and make it executable by using sudo chmod +x /bin/switchphp .
You can now switch your PHP versions by using the following commands:
switchphp 7 or switchphp 5.6
Note that you must have both PHP versions installed, of course. :)