Last active
May 1, 2018 13:05
-
-
Save matthbull/34749c2d9cc3500dd83e to your computer and use it in GitHub Desktop.
Wraps `phpbrew switch xx` in a shell script to facilitate automatic php switching in apache as well as the standard cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# wraps phpbrew switch to enable apache switching | |
# Author: Matt Holbrook-Bull | |
# | |
# requirements: | |
# /etc/apache2/modules must be writable | |
# you must have apxs2 extension compiled into your php installs | |
# "chmod +x switchphp.sh" - to make executable | |
# | |
# usage: | |
# ./switchphp.sh 5.6 | |
# | |
# notes: | |
# dont run with sudo, if you need to then /etc/apache2 isnt writable, or you installed phpbrew with sudo (which you shouldnt) | |
# change the 'so' filenames to match the lib files in '/usr/lib/apache2/modules' as per your install | |
# youll need to restart apache after running | |
# fail commands gracefully | |
set -e | |
set -o pipefail | |
source ~/.bashrc | |
module_path=/usr/lib/apache2/modules | |
if [ $1 ]; then | |
echo "switching php to version ${1}..." | |
if [ $1 = "5.5" ]; then | |
set=5 | |
version="5.5.38" | |
so_path=libphp5.5.38.so | |
fi | |
if [ $1 = "5.6" ]; then | |
set=5 | |
version="5.6.27" | |
so_path=libphp5.6.27.so | |
fi | |
if [ $1 = "7.1" ]; then | |
set=7 | |
version="7.1.15" | |
so_path=libphp7.1.15.so | |
fi | |
if [ $1 = "7.2" ]; then | |
set=7 | |
version="7.2.3" | |
so_path=libphp7.2.3.so | |
fi | |
fi | |
echo "version selected = ${version}" | |
if [ -v version ]; then | |
source $HOME/.phpbrew/bashrc | |
phpbrew switch php-${version} | |
echo "" > /etc/apache2/mods-available/php7.load | |
echo "" > /etc/apache2/mods-available/php5.load | |
echo "LoadModule php${set}_module $module_path/${so_path}" > /etc/apache2/mods-available/php${set}.load | |
sudo service apache2 restart | |
else | |
echo "no version set" | |
echo "versions available: 5.5 5.6 7.1 7.2" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment