Skip to content

Instantly share code, notes, and snippets.

@a904guy
Last active September 18, 2017 06:16
Show Gist options
  • Save a904guy/5c257669577faf52b684e9dc30d92263 to your computer and use it in GitHub Desktop.
Save a904guy/5c257669577faf52b684e9dc30d92263 to your computer and use it in GitHub Desktop.
Installs PHP PPA. Versions: 5.6, 7.0, 7.1, 7.2. Installs php-cli, php-pear, php-fpm
#!/usr/bin/env bash
# Possible to pass version as first arg of the script
# ./install_php 7.2 (Latest Available)
versions="5.6 7.0 7.1 7.2"
## Parse first arg or else ask which version to install
if [ $1 ];
then
echo "Selected PHP Version: $1"
version=$1
else
echo -n "Which version do you want to install? Options: ($versions): "
read version
fi
if [[ $versions != *"$version"* ]];
then
echo "Please select one of the following versions: $versions"
exit 1
fi
## Validate version is acceptable
## Install ppa, update, then install base php version packages
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install php$version-cli php$version-dev php$version-fpm php-pear -y -m
## Check if installed globally or give prompt to.
folder="$(dirname $0)";
if [ "$folder" != "/usr/local/bin" ];
then
echo "Install script to global path to run anywhere? [y/n]: "
read install
if [ "${install,,}" = "y" ];
then
sudo -H rm -f /usr/local/bin/install_php
sudo -H cp "$0" /usr/local/bin/install_php
echo "Installed. You can run as 'install_php' now from anywhere."
fi
fi
echo "All Done, Enjoy"
# Author: Andy Hawkins
# Company: Hawkins.Tech
# Email: YW5keUBoYXdraW5zLnRlY2g=
# Discord: https://discord.gg/ggbtaA8
@a904guy
Copy link
Author

a904guy commented Sep 16, 2017

Easy install: bash <(curl -L http://install_php.src.sh)

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