Skip to content

Instantly share code, notes, and snippets.

@jakeydevs
Last active November 21, 2018 05:27
Show Gist options
  • Save jakeydevs/486f487672f9291cc95f0b677f22800c to your computer and use it in GitHub Desktop.
Save jakeydevs/486f487672f9291cc95f0b677f22800c to your computer and use it in GitHub Desktop.
Update script to turn PHP 7.0 to 7.2 - blog post explaning at wildrocket.io/
#! /bin/bash
# Please only run IF YOU ARE SURE YOU SHOULD!
#
# This script will remove PHP and attempt to install the latest
# "Stable" version! To help me with LARAVEL installations, it'll
# also install composer and turn on mod_rewrite as well if it cannot
# be sure it is installed
#
# @author @JakeLPrice
# @created 25 July 2018
# 1. Add Ondrejs PPA Repo and update
echo "$(tput setaf 2)1. Add Ondrejs PPA Repo and update...$(tput sgr 0)"
sudo add-apt-repository ppa:ondrej/php -y -u > /dev/null 2>&1
# 2. Remove default PHP 7.0
echo "$(tput setaf 2)2. Update PHP to latest$(tput sgr 0)"
sudo apt-get purge php7.0 php7.0-common -y > /dev/null 2>&1
# 3. Add other PHP Packages for Laravel
echo "$(tput setaf 2)3. Adding PHP packages$(tput sgr 0)"
sudo apt-get install php7.2-curl php7.2-xml php7.2-zip php7.2-gd php7.2-mysql php7.2-mbstring -y > /dev/null 2>&1
# 4. OPTIONAL - add composer if not installed
command -v composer >/dev/null 2>&1 || {
echo "$(tput setaf 2)OPTIONAL. Composer not installed. Installing...$(tput sgr 0)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php > /dev/null 2>&1
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
}
# 5. OPTIONAL - turn on mod_rewrite
a2enmod rewrite > /dev/null 2>&1
service apache2 restart
# 6. Done
echo "$(tput setaf 2)Completed! - PHP version is reporting it is version:$(tput sgr 0)"
php -v
echo "$(tput setaf 2)<3 from wildrocket.io$(tput sgr 0)"
@jakeydevs
Copy link
Author

Updated to remove the prompt asking to run!

@efinal
Copy link

efinal commented Aug 9, 2018

the actual php7.2 installation has been missed? sudo apt-get install php7.2 php7.2-common?

@jakeydevs
Copy link
Author

No, not at all - the server will install it when you purge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment