在mac下用mac homebrew nginx安装nginx后,怎么添加第三方module

0 Homebrew是啥?
&Homebrew installs the stuff you need that Apple didn&t.&&Homebrew 使 OS X 更完整&。
Homebrew的官网(多语言版本)简单明了地介绍了如何安装和使用这个工具,并提供了自己的Wiki。
1 安装Homebrew&
brew的安装很简单,使用一条ruby命令即可,Mac系统上已经默认安装了ruby。gerryyang@mba:bin$ruby --versionruby 2.0.0p247 ( revision 41674) [universal.x86_64-darwin13]关于安装brew的详细说明可以参考其github上的wiki说明:
"Installation
The suggested and easiest way to install Homebrew is on the&. We don&t duplicate it here because it is asecurity risk to list it on a user-editable wiki.
The standard script installs Homebrew to&/usr/local&so that&&when youbrew install. It is acareful script, it can be run even if you have stuff installed to/usr/local&already. It tells you exactly what it will do before itdoes it too. And you have to confirm everything it will do before itstarts.
There are other ways to install Homebrew which provide you with moreflexibility. They are listed below the requirements.
gerryyang@mba:~$ruby&-e&"$(curl&-fsSL&/Homebrew/homebrew/go/install)"&&
It&appears&Homebrew&is&already&installed.&If&your&intent&is&to&reinstall&you&&
should&do&the&following&before&running&this&installer&again:&&
&&&&rm&-rf&/usr/local/Cellar&/usr/local/.git&&&&brew&cleanup&&
由于我的系统上已经安装过brew,因此再次执行安装命令会提示我brew已经存在。
2 Homebrew的用法&
查看brew的具体用法:
gerryyang@mba:~$brew&&
Example&usage:&&
&&brew&[info&|&home&|&options&]&[FORMULA...]&&
&&brew&install&FORMULA...&&
&&brew&uninstall&FORMULA...&&
&&brew&search&[foo]&&
&&brew&list&[FORMULA...]&&
&&brew&update&&
&&brew&upgrade&[FORMULA...]&&
&&brew&pin/unpin&[FORMULA...]&&
Troubleshooting:&&
&&brew&doctor&&
&&brew&install&-vd&FORMULA&&
&&brew&[--env&|&--config]&&
Brewing:&&
&&brew&create&[URL&[--no-fetch]]&&
&&brew&edit&[FORMULA...]&&
&&open&/Homebrew/homebrew/wiki/Formula-Cookbook&&
Further&help:&&
&&man&brew&&
&&brew&home&&
gerryyang@mba:~$&&
3 Homebrew的有趣问题
下面关于Homebrew的一些常见问题:
(1) 在OS X中找不到想要的软件,可以使用brew安装;
gerryyang@mba:~$brew&install&wget&&
==&&Downloading&http://ftpmirror.gnu.org/wget/wget-1.14.tar.gz&&
########################################################################&100.0%&&
==&&./configure&--prefix=/usr/local/Cellar/wget/1.14&--sysconfdir=/usr/local/etc&&
==&&make&install&&
Warning:&Could&not&link&wget.&Unlinking...&&
Error:&The&`brew&link`&step&did&not&complete&successfully&&
The&formula&built,&but&is&not&symlinked&into&/usr/local&&
You&can&try&again&using&`brew&link&wget'&&
Possible&conflicting&files&are:&&
/usr/local/bin/wget&&
/usr/local/share/man/man1/wget.1&&
==&&Summary&&
&span&style="font:&13.0px&Monaco"&/usr/local/Cellar/wget/1.14:&8&files,&688K,&built&in&2.3&minutes&/span&&&&
由于之前使用源码方式安装过wget,因此再用brew安装时会提示冲突的错误,因为/usr/locat/bin/wget已经存在。实际上,Homebrew 将软件包分装到单独的目录(/usr/local/Cellar),然后 symlink 到&/usr/local&中。&(2) 如何更新本地已安装的package呢?第一步:先更新brew:
brew update
gerryyang@mba:bin$brew&update&&
Already&up-to-date.&&
第二步:更新所有package:brew upgarde
gerryyang@mba:bin$brew&upgrade&&
==&&Upgrading&1&outdated&package,&with&result:&&
wget&1.15&&
==&&Upgrading&wget&&
==&&Installing&wget&dependency:&openssl&&
==&&Downloading&https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0&&
########################################################################&100.0%&&
==&&Pouring&openssl-1.0.1f.mavericks.bottle.tar.gz&&
==&&Caveats&&
This&formula&is&keg-only,&so&it&was&not&symlinked&into&/usr/local.&&
Mac&OS&X&already&provides&this&software&and&installing&another&version&in&&
parallel&can&cause&all&kinds&of&trouble.&&
The&OpenSSL&provided&by&OS&X&is&too&old&for&some&software.&&
Generally&there&are&no&consequences&of&this&for&you.&If&you&build&your&&
own&software&and&it&requires&this&formula,&you'll&need&to&add&to&your&&
build&variables:&&
&&&&LDFLAGS:&&-L/usr/local/opt/openssl/lib&&
&&&&CPPFLAGS:&-I/usr/local/opt/openssl/include&&
==&&security&find-certificate&-a&-p&/Library/Keychains/System.keychain&&&'/usr/l&&
==&&security&find-certificate&-a&-p&/System/Library/Keychains/SystemRootCertific&&
==&&mv&-f&/usr/local/etc/openssl/osx_cert.pem.tmp&/usr/local/etc/openssl/osx_cer&&
==&&Summary&&
/usr/local/Cellar/openssl/1.0.1f:&429&files,&15M&&
==&&Installing&wget&&
==&&Downloading&http://ftpmirror.gnu.org/wget/wget-1.15.tar.gz&&
########################################################################&100.0%&&
==&&./configure&--prefix=/usr/local/Cellar/wget/1.15&--sysconfdir=/usr/local/etc&--with-ssl=openssl&--with-libssl-prefix=/usr/local/opt/openssl&--disable-iri&&
==&&make&install&&
Warning:&Could&not&link&wget.&Unlinking...&&
Error:&The&`brew&link`&step&did&not&complete&successfully&&
The&formula&built,&but&is&not&symlinked&into&/usr/local&&
You&can&try&again&using&`brew&link&wget'&&
Possible&conflicting&files&are:&&
/usr/local/bin/wget&&
/usr/local/share/man/man1/wget.1&&
==&&Summary&&
/usr/local/Cellar/wget/1.15:&8&files,&700K,&built&in&73&seconds&&
gerryyang@mba:bin$&&
(3) 如何删除Homebrew?
If you installed to&/usr/local&then you can use the script in&&to uninstall & it will onlyremove Homebrew and the stuff Homebrew installed leaving anything elsein/usr/local&alone.
Provided you haven&t put anything else in Homebrew&s prefix(brew --prefix), you can generally justrm -rf&that directory. Thisis because Homebrew won&t touch files outside its prefix.
(4) Homebrew下载的package存放的路径在哪里?
gerryyang@mba:bin$brew&--cache&&
/Library/Caches/Homebrew&&
gerryyang@mba:bin$ls&/Library/Caches/Homebrew/&&
Formula/&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&wget-1.14.tar.gz&&
coreutils-8.22.tar.xz&&&&&&&&&&&&&&&&&&wget-1.15.tar.gz&&
openssl-1.0.1f.mavericks.bottle.tar.gz&&xz-5.0.5.mavericks.bottle.2.tar.gz&&
gerryyang@mba:bin$ls&/Library/Caches/Homebrew/Formula/&&
coreutils.brewing&&openssl.brewing&&wget.brewing&&xz.brewing&&
gerryyang@mba:bin$&&
(5) 我可以安装自己的stuff在/usr/local吗?
Yes, brew is designed to not get in your way so you can use it how youlike.
Install your own stuff, but be aware that if you install commonlibraries, like libexpat yourself, it may cause trouble when trying tobuild certain Homebrew formula. As a resultbrew doctor&will warn youabout this.
Thus it&s probably better to install your own stuff to the Cellar andthen&brew link&it. Like so:
$ cd foo-0.1
$ brew diy
./configure &prefix=/usr/local/Cellar/foo/0.1
$ ./configure &prefix=/usr/local/Cellar/foo/0.1
$ make && make install
$ brew link foo
Linking /usr/local/Cellar/foo/0.1& 17 symlinks created
在我的环境上检测是这样的:
gerryyang@mba:bin$brew&doctor&&
Warning:&Unbrewed&dylibs&were&found&in&/usr/local/lib.&&
If&you&didn't&put&them&there&on&purpose&they&could&cause&problems&when&&
building&Homebrew&formulae,&and&may&need&to&be&deleted.&&
Unexpected&dylibs:&&
&&&&/usr/local/lib/libboost_atomic.dylib&&
&&&&/usr/local/lib/libboost_chrono.dylib&&
&&&&/usr/local/lib/libboost_context.dylib&&
&&&&/usr/local/lib/libboost_date_time.dylib&&
&&&&/usr/local/lib/libboost_filesystem.dylib&&
&&&&/usr/local/lib/libboost_graph.dylib&&
&&&&/usr/local/lib/libboost_iostreams.dylib&&
&&&&/usr/local/lib/libboost_locale.dylib&&
&&&&/usr/local/lib/libboost_log.dylib&&
&&&&/usr/local/lib/libboost_math_c99.dylib&&
&&&&/usr/local/lib/libboost_math_c99f.dylib&&
&&&&/usr/local/lib/libboost_math_c99l.dylib&&
&&&&/usr/local/lib/libboost_math_tr1.dylib&&
&&&&/usr/local/lib/libboost_math_tr1f.dylib&&
&&&&/usr/local/lib/libboost_math_tr1l.dylib&&
&&&&/usr/local/lib/libboost_prg_exec_monitor.dylib&&
&&&&/usr/local/lib/libboost_program_options.dylib&&
&&&&/usr/local/lib/libboost_python.dylib&&
&&&&/usr/local/lib/libboost_random.dylib&&
&&&&/usr/local/lib/libboost_regex.dylib&&
&&&&/usr/local/lib/libboost_serialization.dylib&&
&&&&/usr/local/lib/libboost_signals.dylib&&
&&&&/usr/local/lib/libboost_system.dylib&&
&&&&/usr/local/lib/libboost_thread.dylib&&
&&&&/usr/local/lib/libboost_timer.dylib&&
&&&&/usr/local/lib/libboost_unit_test_framework.dylib&&
&&&&/usr/local/lib/libboost_wave.dylib&&
&&&&/usr/local/lib/libboost_wserialization.dylib&&
Warning:&Unbrewed&static&libraries&were&found&in&/usr/local/lib.&&
If&you&didn't&put&them&there&on&purpose&they&could&cause&problems&when&&
building&Homebrew&formulae,&and&may&need&to&be&deleted.&&
Unexpected&static&libraries:&&
&&&&/usr/local/lib/libboost_atomic.a&&
&&&&/usr/local/lib/libboost_chrono.a&&
&&&&/usr/local/lib/libboost_context.a&&
&&&&/usr/local/lib/libboost_coroutine.a&&
&&&&/usr/local/lib/libboost_date_time.a&&
&&&&/usr/local/lib/libboost_exception.a&&
&&&&/usr/local/lib/libboost_filesystem.a&&
&&&&/usr/local/lib/libboost_graph.a&&
&&&&/usr/local/lib/libboost_iostreams.a&&
&&&&/usr/local/lib/libboost_locale.a&&
&&&&/usr/local/lib/libboost_log.a&&
&&&&/usr/local/lib/libboost_math_c99.a&&
&&&&/usr/local/lib/libboost_math_c99f.a&&
&&&&/usr/local/lib/libboost_math_c99l.a&&
&&&&/usr/local/lib/libboost_math_tr1.a&&
&&&&/usr/local/lib/libboost_math_tr1f.a&&
&&&&/usr/local/lib/libboost_math_tr1l.a&&
&&&&/usr/local/lib/libboost_prg_exec_monitor.a&&
&&&&/usr/local/lib/libboost_program_options.a&&
&&&&/usr/local/lib/libboost_python.a&&
&&&&/usr/local/lib/libboost_random.a&&
&&&&/usr/local/lib/libboost_regex.a&&
&&&&/usr/local/lib/libboost_serialization.a&&
&&&&/usr/local/lib/libboost_signals.a&&
&&&&/usr/local/lib/libboost_system.a&&
&&&&/usr/local/lib/libboost_test_exec_monitor.a&&
&&&&/usr/local/lib/libboost_thread.a&&
&&&&/usr/local/lib/libboost_timer.a&&
&&&&/usr/local/lib/libboost_unit_test_framework.a&&
&&&&/usr/local/lib/libboost_wave.a&&
&&&&/usr/local/lib/libboost_wserialization.a&&
Warning:&You&have&unlinked&kegs&in&your&Cellar&&
Leaving&kegs&unlinked&can&lead&to&build-trouble&and&cause&brews&that&depend&on&&
those&kegs&to&fail&to&run&properly&once&built.&Run&`brew&link`&on&these:&&
&&&&wget&&
gerryyang@mba:bin$&&
(6) 为什么选择Homebrew这个名字?mxcl was too concerned with the beer theme and didn&t consider that the project may actually prove popular. By the time he realized it was too late. However, today, the first google hit for &homebrew& -)
看来作者是个酒鬼!(7) 关于更多地QA可以参考Homebrew的Wiki
(8) 一些常用安装推荐
gerryyang@mba:bin$brew&list&&
coreutils&&openssl&&wget&&xz&&
Introduction to Coreutils&
The GNU Core Utilities are the basic file, shell and text manipulationutilities of the GNU operating system.These are the core utilitieswhich are expected to exist on every operating system.
[1]&http://brew.sh/index_zh-cn.html[2]&/Homebrew/homebrew/wiki/Installation[3]&/Homebrew/homebrew/wiki/FAQ[4]&/Homebrew/homebrew/wiki
阅读(...) 评论()Homebrew--MAC下包管理工具和软件安装工具 - 为程序员服务
Homebrew--MAC下包管理工具和软件安装工具
是MAC下的包管理工具,可以当做debian下的apt-get,但要强大得多。它尽可能的利用系统自带库,大大缩短编译时间;冗余库极少,软件包的管理清晰灵活;安装脚本完全用ruby编写,极易自由定制
一键安装(一键脚本请参照官网,可能略有不同):
ruby -e "$(curl -fsSL /Homebrew/install/master/install)"
安装完毕后执行brew,输出如下,列出了 brew 的一些用法。
Example usage:
brew [info | home | options ] [FORMULA...]
brew install FORMULA...
brew uninstall FORMULA...
brew search [foo]
brew list [FORMULA...]
brew update
brew upgrade [FORMULA...]
brew pin/unpin [FORMULA...]
Troubleshooting:
brew doctor
brew install -vd FORMULA
brew [--env | config]
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
Further help:
可以方便的搜索、查看和安装和卸载软件,如下图所示:
brew actions
按照官方的介绍:
Homebrew installs
that Apple didn’t. 是MAC OS生态的重要补充,提供了大量在Linux下喜闻乐见的工具,比如curl, rename, wget等等;
Homebrew installs packages to their own directory and then symlinks their files into /usr/local. 通过 brew 安装的软件可以和系统原软件完美兼容,互不影响;
Homebrew won’t install files outside its prefix, and you can place a Homebrew installation wherever you like. homebrew 安装的文件默认全部在其指定的目录下,不会安装在其他位置。方便删除,可以自定义 homebrew 的安装位置;
Trivially create your own Homebrew packages. 方便的创建个人包;
It’s all git and ruby underneath, so hack away with the knowledge that you can easily revert your modifications and merge upstream updates. 通过git管理所有安装配置,极易创建「私服」,把官方repo作为上游分支,可以自由定制。
# brew edit wget 可以直接编辑wget的安装配置
class Wget & Formula
homepage "https://www.gnu.org/software/wget/"
url "https://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz"
sha256 "5bdddc053ad7d0ed2aa89b4b630f76785bac21695fcd"
def install
system "./configure", "--prefix=#{prefix}"
system "make", "install"
我安装的软件有:
& brew list | paste -sd ',' -
aspell,autoconf,autojump,automake,bash,boris,brew-cask,ccat,cloog,cmake,composer,coreutils,cscope,ctags,editorconfig,emacs-clang-complete-async,emacs-mac,fontconfig,freetype,gcc,gdbm,gettext,git,gmp,gnu-sed,gnutls,go,htop-osx,icu4c,imagemagick,isl,jpeg,leptonica,libevent,libmpc,libpng,libtasn1,libtiff,libtool,llvm,mercurial,mobile-shell,mpfr,nettle,newt,nvm,openssl,pcre,php56,pkg-config,popt,protobuf,proxychains-ng,pyenv,pyqt,python,qt,rbenv,rbenv-gem-rehash,readline,rename,ruby-build,s-lang,sip,sqlite,tesseract,the_silver_searcher,tig,tree,unixodbc,vim,wget,xz,zeromq,zlib,zsh
PS: 当希望用 brew 安装的软件替代系统自带的软件(比如 git)时,确保$PATH中 brew 安装的位置在系统位置/usr/bin之前,可以运行brew doctor查看。安装软件完成之后请查看安装成功的一些后续指导。
PS: 执行brew cleanup清除安装产生的缓存文件。
管理 brew 安装的 service。
Homebrew Cask
(brew cask) 构建于 Homebrew,继承了其优雅和便捷性,提供安装 OS X 应用和二进制软件的新方法。可以这么简单理解,brew安装的是命令行工具,比如curl, rename, wget;brew cask安装的是应用软件,比如google chrome, dropbox等。通过brew cask 安装软件,只需要简单的一条命令brew cask install google-chrome即可,再也不需要以前的打开网页、找到链接、下载软件、解压包、放到程序目录,删除安装文件,再来启动它这么复杂的步骤了。一键完成!
虽然通过 Mac App Store 安装软件一样很简单,但是 Mac App Store 生态圈远不完善,审核流程过长,限制太多,维护成本过高让很多应用开发者被迫离开。大量软件缺失。
安装brew install caskroom/cask/brew-cask,安装完毕后执行brew cask,可以看到 cask 提供的命令基本上继承自 brew:
& brew cask
brew-cask provides a friendly homebrew-style CLI workflow for the
administration of Mac applications distributed as binaries.
!! no command verb:
displays note about new built-in alfred support
verifies installability of Casks
dump raw source of the given Cask to the standard output
cleans up cached downloads and tracker symlinks
creates the given Cask and opens it in an editor
checks for configuration issues
edits the given Cask
downloads Cask resources to local cache
opens the homepage of the given Cask
displays information about the given Cask
installs the given Cask
with no args, lists installed C given installed Casks, lists staged files
searches all known Casks
uninstalls the given Cask
a synonym for 'brew update'
zaps all files associated with the given Cask
See also "man brew-cask"
通过 brew 安装的软件都在/opt/homebrew-cask/Caskroom下:
& cd /opt/homebrew-cask/Caskroom
/opt/homebrew-cask/Caskroom
aliwangwang
sourcetree
virtualbox
google-chrome
bettertouchtool
haskell-platform p4merge
tunnelblick
xtrafinder
同时在~/Applications下创建了链接文件:
& ll ~/Applications
lrwxr-xr-x
62B Jun 13
2014 AliWangwang.app -& /opt/homebrew-cask/Caskroom/aliwangwang/latest/AliWangwang.app
你也可以像 brew 那样自由定制,假如你觉得某个软件全球的用户都需要,就可以向官方 repo 发起 pull request。
cask :v1 =& 'dropbox' do
version :latest
sha256 :no_check
url '/download?plat=mac&full=1'
name 'Dropbox'
homepage '/'
license :gratis
app 'Dropbox.app'
zap :delete =& '~/.dropbox'
更有趣的是,你的重装系统将变得极为简单!把你的常用软件列表记下来,然后执行brew cask install software-1 software-2 ... software-n,然后睡一觉就一切搞定了~ 个人文档数据通过dropbox直接恢复~你的代码肯定都在 github~
PS: cask 重装软件,brew cask uninstall xxx && brew cask install xxx或brew cask install xxx --force。
PS: alfred 支持,brew cask alfred link。
PS: brew 和 brew cask 的下载都是断点续传的。
这是我的中文博客,记录自己在技术、生活等方面的一些感想。博客叫 Storm Spirit, 因为我特别喜欢 Dota 里蓝猫这个英雄,可惜玩得不好…… 希望自己能够通过博客,得到成长。
原文地址:, 感谢原作者分享。
您可能感兴趣的代码我用MAC也有两个多月了,直到看到这篇博客才算真正找到了感觉~
前面的LNMP应该改成UNMP才是
以下是正文~
Brew 是 Mac 下面的包管理工具,通过 Github 托管适合 Mac 的编译配置以及 Patch,可以方便的安装开发工具。 Mac 自带ruby 所以安装起来很方便,同时它也会自动把git也给你装上。官方网站:&。
安装完成之后,建议执行一下自检,brew doctor如果看到Your system is ready to brew.&那么你的brew已经可以开始使用了。
ruby -e &$(curl -fsSL /mxcl/homebrew/go/install)&
brew doctor
常用命令:&(所有软件以PHP5.5为例子)
brew update
brew search php55
brew tap josegonzalez/php
brew install php55
brew remove
brew upgrade php55
brew options php55
brew services list
brew services cleanup
brew services restart php55
注意:brew services 相关命令最好别经常用了,提示会被移除
brew services restart php55
Warning: brew services is unsupported and will be removed soon.
You should use launchctl instead.
Please feel free volunteer to support it in a tap.
Stopping `php55`... (might take a while)
==& Successfully stopped `php55` (label: homebrew.mxcl.php55)
==& Successfully started `php55` (label: homebrew.mxcl.php55)
ohmyzsh & iTerm2两个神器,在Mac os x下是一定要装的. 两组配合起来使用,加上插件。简直是神一样的存在。 秒杀梅西,内马尔啊:)&
安装 oh my zsh
curl -L http://install.ohmyz.sh | sh
设置默认shell
查看系统支持的shell列表,Mac 10.9.4 自带了 zsh 5.0.2,Linux上得安装。
cat /etc/shells
zsh --version
zsh 5.0.2 (x86_64-apple-darwin13.0)
chsh -s /bin/zsh
虽然Mac自带了zsh,如果你想要最新版的zsh,那么你用&brew install zsh安装一个最新的吧。/usr/local/bin/zsh --version zsh 5.0.5 (x86_64-apple-darwin13.3.0)&区别也不会很大, 默认的版本已经很新了。
homebrew-cask
安装cask:
brew tap phinze/homebrew-cask && brew install brew-cask
cask常用命令:
brew cask search
brew cask search php
brew cask list
brew cask info phpstorm
brew cask uninstall qq
这里谈谈cask对比Mac App Store的优势:
对常用软件支持更全面(特别是开发者),cask里面会给你一些惊喜;软件更新速度快,一般都是最新版本 Store上很久很久才会更新版本;命令安装感觉比打开Store方便,另外Store在国内的速度也是XXOO。
安装iTerm2:
brew cask install iterm2
上面提过的神器组合,更多使用方法请参考, 这里就不详细说明了。
安装开发常用的包&软件
安装开发包
brew install wget watch tmux cmake openssl imagemagick graphicsmagick gearman geoip readline autoconf multitail source-highlight autojump zsh-completions sshfs
升级一下系统自带的vim
brew install ctags macvim --env-std --override-system-vim
安装常用软件
brew cask install alfred appcleaner firefox google-chrome phpstorm sublime-text sequel-pro sketch mplayerx thunder qq
Alfred 是个很不错的东西,推荐必须安装。它默认搜索目录不包含brew cask安装的软件,因此手动将/opt/homebrew-cask添加到Alfred的搜索目录
MySQL PHP Nginx Redis Memcache
前面做了这么多的准备工作,其实 zsh iTerm2 brew 等等这些由于篇幅以及能力有限,一时半会也讲不完,更多选择,更多欢乐,就在Google search,现在才入正题。come on :)
brew install mysql
MySQL开机启动:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
安装完成之后开启MySQL安全机制:
/usr/local/opt/mysql/bin/mysql_secure_installation
根据终端提示,输入root密码,然后依次确认一些安全选项。具体信息可以参考
ps aux | grep mysql
0:00.31 /usr/local/Cellar/mysql/5.6.19/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.6.19 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.6.19/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/CalvinsMacBook-Pro.local.err --pid-file=/usr/local/var/mysql/CalvinsMacBook-Pro.local.pid --socket=/tmp/mysql.sock --port=3306
0:00.04 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --bind-address=127.0.0.1 --datadir=/usr/local/var/mysql
mysql -uroot -p
Welcome to the MySQL monitor.
Commands end or \g.
Your MySQL connection id is 23
Server version: 5.6.19-log Homebrew
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type '' or '\h' for help. Type '\c' to clear the current input statement.
安装phpmyadmin
brew install phpmyadmin
添加brew的PHP扩展库:
brew update
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
可以使用brew options php55命令来查看安装php5.5的选项,这里我用下面的选项安装:
brew install php55 --with-fpm --with-gmp --with-imap --with-tidy --with-debug --with-mysql --with-libmysql
PHP编译过程中如果遇到configure: error: Cannot find OpenSSL's &evp.h&错误,执行xcode-select --install&重新安装一下Xcode Command Line Tools在上有关于这个讨论:
For future reference of anybody looking for Command Line Tools with Xcode 5, open up a Terminal window and type xcode-select --install. A window will appear informing you command line tools are required. Click Install and you should be good to go
等待PHP编译完成,开始安装PHP常用扩展,扩展安装过程中brew会自动安装依赖包,例如php55-pdo-pgsql&会自动装上postgresql,这里我安装以下PHP扩展:
brew install php55-apcu\
php55-gearman\
php55-geoip\
php55-gmagick\
php55-imagick\
php55-intl\
php55-mcrypt\
php55-memcache\
php55-memcached\
php55-mongo\
php55-opcache\
php55-pdo-pgsql\
php55-phalcon\
php55-redis\
php55-sphinx\
php55-swoole\
php55-uuid\
扩展里面提一下&和&.
一个是C语言写的PHP框架,安装来个人摸索熟悉一下,还没有真正的使用过,大致看了一下文档,感觉非常吊炸天。目前公司的项目是基于Yii2的,也看看这个框架。 另外一个,貌似不错,可能在项目中会考虑用到它。
由于Mac自带了php和php-fpm,因此需要添加系统环境变量PATH来替代自带PHP版本。
echo 'export PATH=&$(brew --prefix php55)/bin:$PATH&' && ~/.bash_profile
echo 'export PATH=&$(brew --prefix php55)/sbin:$PATH&' && ~/.bash_profile
echo 'export PATH=&/usr/local/bin:/usr/local/sbib:$PATH&' && ~/.bash_profile
source ~/.bash_profile
测试一下效果:
PHP 5.5.14 (cli) (built: Jul 16 2014 15:43:06) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
/usr/bin/php -v
PHP 5.4.24 (cli) (built: Jan 19 2014 21:32:15)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
php-fpm -v
PHP 5.5.14 (fpm-fcgi) (built: Jul 16 2014 15:43:12) (DEBUG)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
/usr/sbin/php-fpm -v
PHP 5.4.24 (fpm-fcgi) (built: Jan 19 2014 21:32:57)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
修改php-fpm配置文件,vim /usr/local/etc/php/5.5/php-fpm.conf,找到pid相关大概在25行,去掉注释&pid = run/php-fpm.pid, 那么php-fpm的pid文件就会自动产生在/usr/local/var/run/php-fpm.pid,下面要安装的Nginx pid文件也放在这里。
#测试php-fpm配置
php-fpm -t
php-fpm -c /usr/local/etc/php/5.5/php.ini -y /usr/local/etc/php/5.5/php-fpm.conf -t
#启动php-fpm
php-fpm -D
php-fpm -c /usr/local/etc/php/5.5/php.ini -y /usr/local/etc/php/5.5/php-fpm.conf -D
#关闭php-fpm
kill -INT `cat /usr/local/var/run/php-fpm.pid`
#重启php-fpm
kill -USR2 `cat /usr/local/var/run/php-fpm.pid`
#也可以用上文提到的brew命令来重启php-fpm,不过他官方不推荐用这个命令了
brew services restart php55
#还可以用这个命令来启动php-fpm
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
启动php-fpm之后,确保它正常运行监听9000端口:
lsof -Pni4 | grep LISTEN | grep php
30907 calvin
IPv4 0xf11f9e8e
TCP 127.0.0.1:9000 (LISTEN)
30917 calvin
IPv4 0xf11f9e8e
TCP 127.0.0.1:9000 (LISTEN)
30918 calvin
IPv4 0xf11f9e8e
TCP 127.0.0.1:9000 (LISTEN)
30919 calvin
IPv4 0xf11f9e8e
TCP 127.0.0.1:9000 (LISTEN)
PHP-FPM开机启动:
ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist
安装php composer
brew install composer
#检查一下情况
Composer version 1.0.0-alpha8 2014-01-06 18:39:59
redis memcached这些软件brew 已经自动依赖安装上,如果想开机自动启动,或者查看使用说明&brew info redis即可。另外,composer的中文文档:
brew install nginx
Nginx启动关闭命令:
#测试配置是否有语法错误
#打开 nginx
sudo nginx
#重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit
#也可以使用Mac的launchctl来启动|停止
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Nginx开机启动
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Nginx监听80端口需要root权限执行,因此:
sudo chown root:wheel /usr/local/Cellar/nginx/1.6.0_1/bin/nginx sudo chmod u+s /usr/local/Cellar/nginx/1.6.0_1/bin/nginx
配置nginx.conf
创建需要用到的目录:
mkdir -p /usr/local/var/logs/nginx
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d
mkdir -p /usr/local/etc/nginx/ssl
sudo mkdir -p /var/www
sudo chown :staff /var/www
sudo chmod 775 /var/www
vim /usr/local/etc/nginx/nginx.conf&输入以下内容:
worker_processes
/usr/local/var/logs/nginx/error.log debug;
/usr/local/var/run/nginx.
worker_connections
default_type
application/octet-
log_format
'$remote_addr - $remote_user [$time_local] &$request& '
'$status $body_bytes_sent &$http_referer& '
'&$http_user_agent& &$http_x_forwarded_for&';
access_log
/usr/local/var/logs/access.
keepalive_timeout
port_in_redirect off;
include /usr/local/etc/nginx/sites-enabled/*;
设置nginx php-fpm配置文件
vim /usr/local/etc/nginx/conf.d/php-fpm
location ~ \.php$ {
$uri = 404;
fastcgi_pass
127.0.0.1:9000;
fastcgi_index
fastcgi_intercept_errors
include /usr/local/etc/nginx/fastcgi.
nginx虚拟主机准备工作
#创建 info.php index.html 404.html 403.html文件到 /var/www 下面
vi /var/www/info.php
vi /var/www/index.html
vi /var/www/403.html
vi /var/www/404.html
创建默认虚拟主机default
vim /usr/local/etc/nginx/sites-available/default输入:
server_name
/var/www/;
access_log
/usr/local/var/logs/nginx/default.access.
location / {
index.html index.htm index.
/usr/local/etc/nginx/conf.d/php-
location = /info {
127.0.0.1;
rewrite (.*) /.info.
error_page
error_page
创建ssl默认虚拟主机default-ssl
vim /usr/local/etc/nginx/sites-available/default-ssl输入:
server_name
/var/www/;
access_log
/usr/local/var/logs/nginx/default-ssl.access.
ssl_certificate
ssl/localhost.
ssl_certificate_key
ssl/localhost.
ssl_session_timeout
ssl_protocols
SSLv2 SSLv3 TLSv1;
ssl_ciphers
HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers
location / {
/usr/local/etc/nginx/conf.d/php-
location = /info {
127.0.0.1;
rewrite (.*) /.info.
error_page
error_page
创建phpmyadmin虚拟主机
vim /usr/local/etc/nginx/sites-available/phpmyadmin
server_name
/usr/local/share/
/usr/local/var/logs/nginx/phpmyadmin.error.
access_log
/usr/local/var/logs/nginx/phpmyadmin.access.
ssl_certificate
ssl/phpmyadmin.
ssl_certificate_key
ssl/phpmyadmin.
ssl_session_timeout
ssl_protocols
SSLv2 SSLv3 TLSv1;
ssl_ciphers
HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers
location / {
index.html index.htm index.
/usr/local/etc/nginx/conf.d/php-
mkdir -p /usr/local/etc/nginx/ssl
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj &/C=US/ST=State/L=Town/O=Office/CN=localhost& -keyout /usr/local/etc/nginx/ssl/localhost.key -out /usr/local/etc/nginx/ssl/localhost.crt
openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj &/C=US/ST=State/L=Town/O=Office/CN=phpmyadmin& -keyout /usr/local/etc/nginx/ssl/phpmyadmin.key -out /usr/local/etc/nginx/ssl/phpmyadmin.crt
创建虚拟主机软连接,开启虚拟主机
ln -sfv /usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/sites-enabled/default
ln -sfv /usr/local/etc/nginx/sites-available/default-ssl /usr/local/etc/nginx/sites-enabled/default-ssl
ln -sfv /usr/local/etc/nginx/sites-available/phpmyadmin /usr/local/etc/nginx/sites-enabled/phpmyadmin
启动|停止Nginx
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
接下来你可以通过下面这些连接访问:
&-& index.html
&-& info.php via phpinfo();
&-& 404.html
&-& index.html(SSL)
&-& info.php via phpinfo();(SSL)
&-& 404.html(SSL)
&-& phpmyadmin(SSL)
设置快捷服务控制命令
为了后面管理方便,将命令 alias 下,vim ~/.bash_aliases&输入一下内容:
alias nginx.start='launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
alias nginx.stop='launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist'
alias nginx.restart='nginx.stop && nginx.start'
alias php-fpm.start=&launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist&
alias php-fpm.stop=&launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.php55.plist&
alias php-fpm.restart='php-fpm.stop && php-fpm.start'
alias mysql.start=&launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist&
alias mysql.stop=&launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist&
alias mysql.restart='mysql.stop && mysql.start'
alias redis.start=&launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist&
alias redis.stop=&launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.redis.plist&
alias redis.restart='redis.stop && redis.start'
alias memcached.start=&launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist&
alias memcached.stop=&launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist&
alias memcached.restart='memcached.stop && memcached.start'
echo &[[ -f ~/.bash_aliases ]] && . ~/.bash_aliases& && ~/.bash_profile
source ~/.bash_profile
ln -sfv /var/www ~/htdocs
有时间会进一步整理一下,感觉有点乱,第一次在segmentfault上码字,写到一半的时候不小心滑一下触摸板,浏览器后退了,虽然有提示不要离开,点击了不离开之后,Safari白屏。 然后还特地去,
害我白白又浪费很久来写这个博客。希望能帮助到刚刚接触Mac的同学。enjoy Mac‘s development EVN :)
参考资料:
本文已收录于以下专栏:
相关文章推荐
Composer是 PHP 用来管理依赖(dependency)关系的工具。你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件。
1.安装MySQL 由于Mac OS X中并没有预装MySQL,所以需要自己手动安装,我装的是:mysql-5.6.19-osx10.7-x86_64.dmg,具体版本依个人喜好,到mysql官网上选...
mac安装sequelpro遇到的问题:
不像其他dmg镜像一样 打开后有一个拖到应用程序的界面 下载sequelpro后 只能以挂载镜像的方式打开 这样的话 倒是可以用 但一直有一个挂载镜像在哪 不...
注意:不要去删除系统自带的Apache 和php 我开始就删除了系统自带的Apache,导致后面php一直无法安装成功,重装了Apache后才弄好,所以建议不要轻易删除系统自带的Apache和php,...
mac 上安装 python 开发环境
安装 python
安装 virtualenv
virtualenvwrapper
配置virtualenvwrapper文件
virtual...
我用MAC也有两个多月了,直到看到这篇博客才算真正找到了感觉~
前面的LNMP应该改成UNMP才是
转自:/fish/119...
安装Homebrew
最近工作环境切换到Mac,所以以OS X Yosemite(10.10.1)为例,
确保系统已经安装xcode,然后使用一行命令安装依赖管理工具Homebrew
官方网站:...
第一步:Mac OS自带Apache,只需要启动Apache就行。
打开终端,输入命令:sudo apachectl start
第二步:打开浏览器,在地址栏中输入localhost,出现...
自上次翻译了“homebrew”命令后,拖了好久,才写这篇环境搭建,因为平常在公司,只有晚上回去有时间折腾电脑,晚上有时候又有事,或者懒。。,加之穿插了nginx文档的翻译等,还有就是照着教程搭建环境...
用了3年多的本本罢工,最近新入手了一台 rmbp,一堆工作环境要配置,LNMP 里的 NMP 是常规要安装的,恰好也是第一次在 mac 上安装配置 nginx、mysql、php,所以顺便做个记录,免...
他的最新文章
讲师:董岩
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 mac 安装nginx 的文章

 

随机推荐