Skip to content

Instantly share code, notes, and snippets.

@webmasterMeyers
Last active December 2, 2020 16:22
Show Gist options
  • Save webmasterMeyers/6c810fb92ae4ffaa44d824a3cc2503dd to your computer and use it in GitHub Desktop.
Save webmasterMeyers/6c810fb92ae4ffaa44d824a3cc2503dd to your computer and use it in GitHub Desktop.
disable current php and enable php with passed version, usage `$ switch-php 7.4` save this in your ~/.bashrc
#disable current php and enable php with passed version
function switch-php {
sudo a2dismod php$(php -v | grep -o -E '[0-9.]+' -m 1 | cut -c 1-3 | head -n 1);
sudo a2enmod php$1;
sudo update-alternatives --set php /usr/bin/php$1;
sudo update-alternatives --set phar /usr/bin/phar$1;
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$1;
sudo update-alternatives --set phpize /usr/bin/phpize$1;
sudo update-alternatives --set php-config /usr/bin/php-config$1;
sudo service apache2 restart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment