Skip to content

Instantly share code, notes, and snippets.

@rcapile
Last active March 10, 2021 12:40
Show Gist options
  • Save rcapile/fce511e746dff181e9439cbe1a0c24de to your computer and use it in GitHub Desktop.
Save rcapile/fce511e746dff181e9439cbe1a0c24de to your computer and use it in GitHub Desktop.
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install \
libicu64 libmemcached11 \
php7.1-bcmath php7.1-intl php7.1-bz2 php7.1-curl php7.1-mbstring php7.1-mysql php7.1-xml php7.1-soap php7.1-gd php7.1-zip \
php7.1-cli php7.1-json php7.1-opcache php7.1-readline php7.2-xdebug \
php7.2-bcmath php7.2-intl php7.2-bz2 php7.2-curl php7.2-mbstring php7.2-mysql php7.2-xml php7.2-soap php7.2-gd php7.2-zip \
php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline php7.2-xdebug \
php7.3-bcmath php7.3-intl php7.3-bz2 php7.3-curl php7.3-mbstring php7.3-mysql php7.3-xml php7.3-soap php7.3-gd php7.3-zip \
php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline php7.3-xdebug \
php7.4-bcmath php7.4-intl php7.4-bz2 php7.4-curl php7.4-mbstring php7.4-mysql php7.4-xml php7.4-soap php7.4-gd php7.4-zip \
php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline php7.3-xdebug \
php8.0-bcmath php8.0-intl php8.0-bz2 php8.0-curl php8.0-mbstring php8.0-mysql php8.0-xml php8.0-soap php8.0-gd php8.0-zip \
php8.0-cli php8.0-common php8.0-opcache php8.0-readline php8.0-xdebug \
php7.4-redis php8.0-redis php7.4-memcached php8.0-memcached
sudo apt install libapache2-mod-php7.1 libapache2-mod-php7.2 libapache2-mod-php7.3 libapache2-mod-php7.4 libapache2-mod-php8.0
sudo cp /usr/lib/php/7.1/php.ini-development /etc/php/7.1/cli/php.ini
sudo cp /usr/lib/php/7.2/php.ini-development /etc/php/7.2/cli/php.ini
sudo cp /usr/lib/php/7.3/php.ini-development /etc/php/7.3/cli/php.ini
sudo cp /usr/lib/php/7.4/php.ini-development /etc/php/7.4/cli/php.ini
sudo cp /usr/lib/php/8.0/php.ini-development /etc/php/8.0/cli/php.ini
sudo cp /usr/lib/php/7.1/php.ini-development /etc/php/7.1/apache2/php.ini
sudo cp /usr/lib/php/7.2/php.ini-development /etc/php/7.2/apache2/php.ini
sudo cp /usr/lib/php/7.3/php.ini-development /etc/php/7.3/apache2/php.ini
sudo cp /usr/lib/php/7.4/php.ini-development /etc/php/7.4/apache2/php.ini
sudo cp /usr/lib/php/8.0/php.ini-development /etc/php/8.0/apache2/php.ini
sudo cp /usr/lib/php/7.1/php.ini-development /etc/php/7.1/fpm/php.ini
sudo cp /usr/lib/php/7.2/php.ini-development /etc/php/7.2/fpm/php.ini
sudo cp /usr/lib/php/7.3/php.ini-development /etc/php/7.3/fpm/php.ini
sudo cp /usr/lib/php/7.4/php.ini-development /etc/php/7.4/fpm/php.ini
sudo cp /usr/lib/php/8.0/php.ini-development /etc/php/8.0/fpm/php.ini
sudo sh -c 'echo "\nxdebug.remote_enable=1\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.1/apache2/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.2/apache2/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.3/apache2/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.4/apache2/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/8.0/apache2/php.ini'
sudo sh -c 'echo "\nxdebug.remote_enable=1\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.1/cli/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.2/cli/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.3/cli/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/7.4/cli/php.ini'
sudo sh -c 'echo "\nxdebug.mode=develop,debug,coverage\nxdebug.file_link_format=\"phpstorm://open?url=file://%f&line=%l\"" >> /etc/php/8.0/cli/php.ini'
# Ubuntu disables pcntl for security reasons. If you need it...
sudo sed -i 's/disable_functions/;disable_functions/g' /etc/php/7.4/cli/php.ini
sudo sed -i 's/disable_functions/;disable_functions/g' /etc/php/8.0/cli/php.ini
#!/bin/bash
#set -eu
if [ -z ${1+x} ]; then
echo "Usage: switch-php-version.sh version"
exit 1
fi
if [ `whoami` != root ]; then
echo Please run this script as root or using sudo
exit
fi
NewVersion=$1
CurrentVersion=$(php -r '$version = explode(".", PHP_VERSION); echo "{$version[0]}.{$version[1]}";');
if [[ "${CurrentVersion}" == "${NewVersion}" ]]; then
echo "You're already in ${CurrentVersion}"
exit 0;
fi;
echo
echo "Current Version: ${CurrentVersion}"
echo
echo "Disabling apache module"
sudo a2dismod php${CurrentVersion}
echo
echo "Changing PHP Version"
sudo update-alternatives --set php /usr/bin/php$NewVersion
echo
echo "Enabling apache moule"
sudo a2enmod php$NewVersion
sudo service apache2 restart
echo
echo ">> You're now at PHP $NewVersion"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment