forked from jschaedl/sphp-osx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsphp
executable file
·47 lines (36 loc) · 1.22 KB
/
sphp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: sphp [phpversion]"
exit 1
fi
currentversion="`php -r \"echo str_replace('.', '', substr(phpversion(), 0, 3));\"`"
newversion="$1"
brew list php$newversion 2> /dev/null > /dev/null
if [ $? -eq 0 ]; then
echo "PHP version $newversion found"
echo "Stopping PHP-FPM $currentversion"
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php$currentversion.plist
echo "Unlinking old binaries..."
brew unlink php$currentversion 2> /dev/null > /dev/null
echo "Linking new binaries..."
brew link php$newversion
echo "Starting PHP-FPM $currentversion"
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php$newversion.plist
echo "Restarting apache"
pgrep -f /usr/local/opt/httpd24/bin/httpd 2> /dev/null > /dev/null
if [ $? -eq 0 ]; then
echo "Restarting system Apache..."
pkill -9 -f /usr/local/opt/httpd24/bin/httpd
/usr/local/bin/apachectl -k restart > /dev/null 2>&1
fi
pgrep -f /usr/local/Cellar/*/httpd 2> /dev/null > /dev/null
if [ $? -eq 0 ]; then
echo "Restarting homebrew Apache..."
pkill -9 -f /usr/local/Cellar/*/httpd
/usr/local/bin/apachectl -k restart > /dev/null 2>&1
fi
echo "Done."
else
echo "PHP version $newversion was not found."
exit 1
fi