用于简便重新安装Homebrew和PHP的Shell脚本
Mac上的Homebrew非常方便,但是在使用过程中,可能会导致环境混乱,并且逐渐出现无法成功安装软件包的问题。
另外,在家、公司和移动设备的三种环境中,由于版本不匹配,更新可能无法成功。
在这种情况下,最好直接放弃并从头开始重新安装Homebrew,这样就没有后顾之忧了。不过,因为每次输入命令麻烦,所以我将其脚本化了。
顺便也将homebrew-php的安装脚本化。虽然如今可能使用brew bundle更为合适,但将其作为shell脚本可以方便显示消息、创建多种模式等,非常实用。
首先,对Homebrew进行(相对)可靠的卸载。
#!/bin/sh
echo "cd `brew --prefix`"
cd `brew --prefix`
echo "rm -rf Cellar"
rm -rf Cellar
echo "brew prune"
brew prune
echo "rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew"
rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew
echo "rm -rf ~/Library/Caches/Homebrew"
rm -rf ~/Library/Caches/Homebrew
echo "rm -rf ~/Library/Logs/Homebrew"
rm -rf ~/Library/Logs/Homebrew
echo "rm -rf /Library/Caches/Homebrew"
rm -rf /Library/Caches/Homebrew
echo "rm -rf /usr/local/Cellar /usr/local/.git"
rm -rf /usr/local/Cellar /usr/local/.git
下一步是重新安装Homebrew。
#!/bin/sh
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew update
brew doctor
brew -v
MySQL的安装
#!/bin/sh
echo "brew install pkg-config"
brew install pkg-config
echo "mv /usr/local/var/mysql /usr/local/var/mysql.old"
mv /usr/local/var/mysql /usr/local/var/mysql.old
echo "brew install mysql"
brew install mysql
echo "unset TMPDIR"
unset TMPDIR
echo "mkdir /usr/local/var"
mkdir /usr/local/var
echo "mkdir /usr/local/var/mysql"
mkdir /usr/local/var/mysql
echo "mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp"
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
echo "sudo cp /usr/local/opt/mysql/my-new.cnf /etc/my.cnf"
sudo cp /usr/local/opt/mysql/my-new.cnf /etc/my.cnf
echo "$ mysql.server start"
mysql.server start
echo "$ mysql.server stop"
mysql.server stop
全文搜寻mroonga(MySQL+Groonga)的安装(任意选择)
(实际上最近没用到它)
#!/bin/sh
echo "rm -fr /usr/local/share/doc/mroonga"
rm -fr /usr/local/share/doc/mroonga
echo "mysql.server start"
mysql.server start
echo "brew install https://raw.github.com/mroonga/homebrew/master/mroonga.rb --use-homebrew-mysql"
brew install https://raw.github.com/mroonga/homebrew/master/mroonga.rb --use-homebrew-mysql
echo "mysql.server stop"
mysql.server stop
echo "mysql.server start"
mysql.server start
echo "mysql -u root -e'SHOW PLUGINS;'"
mysql -u root -e'SHOW PLUGINS;'
安装memcached
(实际上,也许只需要前三行。我没有跟上世界的变化…)
#!/bin/sh
echo "brew install memcached"
brew install memcached
echo "mkdir -p ~/Library/LaunchAgents"
mkdir -p ~/Library/LaunchAgents
echo "cp /usr/local/Cellar/memcached/1.4.20//homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/"
cp /usr/local/Cellar/memcached/1.4.20//homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
echo "launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist"
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
用PHP5.3安装pecl软件包的方法,包括memcache和apc。如果需要安装pecl memcached,请根据需求进行更改。
#!/bin/sh
echo "rm ~/.pearrc"
rm ~/.pearrc
echo "brew tap homebrew/dupes"
brew tap homebrew/dupes
echo "brew tap homebrew/homebrew-php"
brew tap homebrew/homebrew-php
#echo "brew tap josegonzalez/homebrew-php"
#brew tap josegonzalez/homebrew-php
echo "brew tap homebrew/versions"
brew tap homebrew/versions
echo "brew install libtool zlib jpeg libpng freetype gettext icu4c mcrypt autoconf"
brew install libtool zlib jpeg libpng freetype gettext icu4c mcrypt autoconf
echo "brew install php53-intl"
brew install php53-intl
echo "brew install php53 --with-pgsql --with-intl --with-thread-safety"
brew install php53 --with-pgsql --with-intl --with-thread-safety
touch $(brew --prefix php53)/lib/php/.lock && chmod 0644 $(brew --prefix php53)/lib/php/.lock
echo "pear upgrade"
pear upgrade
echo "pecl install memcache"
pecl install memcache
echo "pecl install apc"
pecl install apc
echo "ln -sf `brew list php53 | grep libphp` /usr/local/lib/libphp5.so"
ln -sf `brew list php53 | grep libphp` /usr/local/lib/libphp5.so
PHP5.5的安装
这里已经安装了opcache和apcu。
(虽然还没有怎么使用过)
#!/bin/sh
echo "rm ~/.pearrc"
rm ~/.pearrc
echo "brew tap homebrew/dupes"
brew tap homebrew/dupes
echo "brew tap homebrew/homebrew-php"
brew tap homebrew/homebrew-php
echo "brew tap homebrew/versions"
brew tap homebrew/versions
echo "brew install libtool zlib jpeg libpng freetype gettext icu4c mcrypt autoconf"
brew install libtool zlib jpeg libpng freetype gettext icu4c mcrypt autoconf
echo "brew install php55-intl"
brew install php55-intl
echo "brew install php55 --with-pgsql --with-intl --with-thread-safety"
brew install php55 --with-pgsql --with-intl --with-thread-safety --with-phpdbg
touch $(brew --prefix php55)/lib/php/.lock && chmod 0644 $(brew --prefix php55)/lib/php/.lock
echo "brew unlink php53"
brew unlink php53
echo "brew link php55"
brew link php55
echo "pear upgrade"
pear upgrade
echo "pecl install memcache"
pecl install memcache
echo "brew install php55-opcache"
brew install php55-opcache
echo "brew install php55-apcu"
brew install php55-apcu
echo "ln -sf `brew list php55 | grep libphp` /usr/local/lib/libphp5.so"
ln -sf `brew list php55 | grep libphp` /usr/local/lib/libphp5.so
要在PHP5.3和PHP5.5之间切换,需要在httpd.conf中将mod_php的加载配置写成以下样式。
LoadModule php5_module /usr/local/lib/libphp5.so
在Github上找到了PHP5.3和PHP5.5的切换方法。(从Github上找到了作为PHP5.3和PHP5.4切换的参考)
#!/bin/bash
#
# php switch for homebrew
#
VERSION_FILE="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/php-switch.version"
if [[ ! -f $VERSION_FILE ]]; then
echo "5.5" > $VERSION_FILE
fi
version=`cat $VERSION_FILE`
if [[ $version == 5.3 ]]; then
ln -sf `brew list php55 | grep libphp` /usr/local/lib/libphp5.so
echo "Switched to 5.5"
echo `brew info php55 | head -1`
echo "5.5" > $VERSION_FILE
brew unlink php53
brew link php55
else
ln -sf `brew list php53 | grep libphp` /usr/local/lib/libphp5.so
echo "Switched to 5.3"
echo `brew info php53 | head -1`
echo "5.3" > $VERSION_FILE
brew unlink php55
brew link php53
fi
sudo apachectl restart
上述内容只是个人的备忘录,不提供任何担保。