Easy PHP version switching command-line script for devilbox
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 | |
# sphp - Easy PHP version switching command-line script for devilbox | |
# Written by: René Kreijveld, email[at]renekreijveld.nl | |
# Version | |
version=1.1 | |
# Available PHP versions in devilbox | |
php_array=(5.2 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0) | |
# Devilbox folder | |
devilbox=/Users/yourusername/devilbox | |
# Has the user submitted a version required | |
if [[ -z "$1" ]]; then | |
echo "PHP version missing" | |
echo "Usage: sphp <version>" | |
echo "Version should be one of:" ${php_array[@]} | |
exit | |
fi | |
# Has the user submitted a non-existing version | |
if [[ ! "${php_array[@]}" =~ "$1" ]]; then | |
echo "Unknown PHP version" | |
echo "Usage: sphp <version>" | |
echo "Version should be one of:" ${php_array[@]} | |
exit | |
fi | |
echo "spsp version ${version}, switching to PHP version $1" | |
cd ${devilbox} | |
# Disable all PHP versions | |
for i in "${php_array[@]}" | |
do | |
perl -pi -e "s/PHP_SERVER=$i/#PHP_SERVER=$i/g" .env | |
perl -pi -e "s/##PHP_SERVER=/#PHP_SERVER=/g" .env | |
done | |
# Enable requested PHP version | |
perl -pi -e "s/#PHP_SERVER=$1/PHP_SERVER=$1/g" .env | |
echo | |
echo "Stopping docker containers:" | |
echo | |
docker-compose stop | |
echo | |
echo "Cleanup docker containers:" | |
echo | |
docker-compose rm -f | |
echo | |
echo "Restart docker containers:" | |
echo | |
docker-compose up -d httpd php mysql | |
echo | |
echo "PHP is now version $1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation instructions
3.1. Edit line #8 to add or remove PHP versions of your devilbox, check these in your devilbox .env file
3.2. Edit line #10 to match the path of your devilbox folder
3.3. Edit line #49 to start the services you want
Usage
Example
This switches devilbox to PHP version 7.3 and restarts the docker containers.