Skip to content

Instantly share code, notes, and snippets.

@nd3w
Last active August 19, 2019 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nd3w/ff2b06464121d1aabec7287f37f00d1a to your computer and use it in GitHub Desktop.
Save nd3w/ff2b06464121d1aabec7287f37f00d1a to your computer and use it in GitHub Desktop.
Linux Aliases to Switch Amongs PHP Versions
Assuming I have three different PHP versions on my system:
1. PHP 5.6
2. PHP 7.1
3. PHP 7.2
To switch two between versions, add these aliases into your ~/.bashrc file:
alias php5671='sudo a2dismod php5.6 ; sudo a2enmod php7.1 ; sudo service apache2 restart ; echo 2 | sudo update-alternatives --config php'
alias php5672='sudo a2dismod php5.6 ; sudo a2enmod php7.2 ; sudo service apache2 restart ; echo 3 | sudo update-alternatives --config php'
alias php7156='sudo a2dismod php7.1 ; sudo a2enmod php5.6 ; sudo service apache2 restart ; echo 1 | sudo update-alternatives --config php'
alias php7172='sudo a2dismod php7.1 ; sudo a2enmod php7.2 ; sudo service apache2 restart ; echo 3 | sudo update-alternatives --config php'
alias php7256='sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart ; echo 1 | sudo update-alternatives --config php'
alias php7271='sudo a2dismod php7.2 ; sudo a2enmod php7.1 ; sudo service apache2 restart ; echo 2 | sudo update-alternatives --config php'
To activate the alias, type command:
source ~/.bashrc
And you're on.
Type 'php5672' in terminal to switch between PHP 5.6 to PHP 7.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment