Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlosoft committed Dec 12, 2020
0 parents commit fb4c3cd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.idea
43 changes: 43 additions & 0 deletions php-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env sh

declare -a php_versions

version=$(php -v | grep -o -e "PHP [0-9+]\.[0-9+]" | cut -d " " -f2)
php_versions=($(brew ls --versions | grep -e "^php" | cut -d " " -f2 | grep -o -e "[0-9+]\.[0-9+]" | xargs))

if [ -z "$1" ]; then
php_versions=$(printf ", %s" "${php_versions[@]}")

echo "Usage: $0 <version>"
echo "PHP Versions: ${php_versions:2}"
exit 0
fi

version_found=0
for php_version in ${php_versions[@]}; do
if [ "${php_version}" = "$1" ]; then
version_found=1
break
fi
done

if [ ${version_found} = 0 ]; then
echo "Specified PHP version $1 is not installed."
exit 1
fi

if [ "${version}" = "$1" ]; then
echo "Cannot change PHP to the same version."
exit 1
fi

apache_conf_file=$(apachectl -V | grep "SERVER_CONFIG_FILE" | cut -d '"' -f 2)
php_module=$(cat ${apache_conf_file} | grep -e "^LoadModule" | grep "libphp")
new_php_module=$(brew info "php@$1" | grep "LoadModule" | grep "libphp" | xargs)

sed -i "" "s#${php_module}#${new_php_module}#g" ${apache_conf_file}
brew unlink php
brew link "php@$1" --force --overwrite
brew services restart httpd

cp "${apache_conf_file}" "${apache_conf_file}.bak"

0 comments on commit fb4c3cd

Please sign in to comment.