Skip to content

Commit fb4c3cd

Browse files
author
Marlosoft
committed
initial commit
0 parents  commit fb4c3cd

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.idea

php-version.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env sh
2+
3+
declare -a php_versions
4+
5+
version=$(php -v | grep -o -e "PHP [0-9+]\.[0-9+]" | cut -d " " -f2)
6+
php_versions=($(brew ls --versions | grep -e "^php" | cut -d " " -f2 | grep -o -e "[0-9+]\.[0-9+]" | xargs))
7+
8+
if [ -z "$1" ]; then
9+
php_versions=$(printf ", %s" "${php_versions[@]}")
10+
11+
echo "Usage: $0 <version>"
12+
echo "PHP Versions: ${php_versions:2}"
13+
exit 0
14+
fi
15+
16+
version_found=0
17+
for php_version in ${php_versions[@]}; do
18+
if [ "${php_version}" = "$1" ]; then
19+
version_found=1
20+
break
21+
fi
22+
done
23+
24+
if [ ${version_found} = 0 ]; then
25+
echo "Specified PHP version $1 is not installed."
26+
exit 1
27+
fi
28+
29+
if [ "${version}" = "$1" ]; then
30+
echo "Cannot change PHP to the same version."
31+
exit 1
32+
fi
33+
34+
apache_conf_file=$(apachectl -V | grep "SERVER_CONFIG_FILE" | cut -d '"' -f 2)
35+
php_module=$(cat ${apache_conf_file} | grep -e "^LoadModule" | grep "libphp")
36+
new_php_module=$(brew info "php@$1" | grep "LoadModule" | grep "libphp" | xargs)
37+
38+
sed -i "" "s#${php_module}#${new_php_module}#g" ${apache_conf_file}
39+
brew unlink php
40+
brew link "php@$1" --force --overwrite
41+
brew services restart httpd
42+
43+
cp "${apache_conf_file}" "${apache_conf_file}.bak"

0 commit comments

Comments
 (0)