用了一年的Mac OS X了,之前不熟悉这个系统,用的是系统自带的PHP以及DMG包安装的MysqL,时间长了,慢慢觉得MacBook的速度跟不上了,虽然关机次数不多,但是每次开机,或者唤醒电脑的时候,系统明显有一定时间的卡顿。特别表现在开机的时候。完全可以去泡一个来一桶了。因此干掉MD101上的光驱,换上256G的Sandisk SSD, 干掉原厂的2G 2,换上8G 2 。 速度应该是杠杠的了,至少可以再服役2年吧。 趁着这次加硬盘的机会,就准备彻底重做开发环境。现在对Mac也有了一定的了解,特地记录一下本次的开发环境安装详情,给自己一个备忘,希望也可以帮助到刚接触Mac 环境的同学们。本开发环境,全部基于安装。 主要软件版本:PHP5.5.14,Nginx 1.6.0,MySQL5.6.19
OS X Mavericks
重新安装系统,在苹果商店下载好OS X Mavericks安装文件,然后准备一支16G的USB3.0 U盘。制作 OSX Mavericks全新安装启动U盘。插上U盘,在终端执行:
untitled 是你的u盘盘符,根据实际情况来。
看到上面的信息说明启动盘制作成功。 安装起来so easy :)
安装完成系统之后, 暂时还没有去迁移文件,由于本人喜好摄影,有大量RAW格式的原图在Aperture 的照片库中,尼康D800一张RAW文件有40M左右,到时候迁移照片库和照片流希望不要掉坑里了。 等开发环境搞定再说了,更新OS X系统到10.9.4 ,然后安装最新的Xcode, 以及在商店买过的软件。确定系统无问题了,进入下一步...
Brew@H_301_18@
Brew 是 Mac 下面的包管理工具,通过 Github 托管适合 Mac 的编译配置以及 Patch,可以方便的安装开发工具。 Mac 自带ruby
所以安装起来很方便,同时它也会自动把git也给你装上。官方网站: ; 。
安装完成之后,建议执行一下自检,brew doctor如果看到
Your system is ready tobrew.那么你的brew已经可以开始使用了。
安装:
代码如下:
自检:
代码如下:
常用命令: (所有软件以PHP5.5为例子)
代码如下:PHP55 #搜索PHP5.5
brew tap josegonzalez/PHP #安装扩展
brew tap #查看安装的扩展列表
brew install PHP55 #安装PHP5.5
brew remove PHP55 #卸载PHP5.5
brew upgrade PHP55 #升级PHP5.5
brew options PHP55 #查看PHP5.5安装选项
brew info PHP55 #查看PHP5.5相关信息
brew home PHP55 #访问PHP5.5官方网站
brew services list #查看系统通过 brew 安装的服务
brew services cleanup #清除已卸载无用的启动配置文件
brew services restart PHP55 #重启PHP-fpm
注意:brew services 相关命令最好别经常用了,提示会被移除
代码如下: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)
Oh My Zsh
ohmyzsh & iTerm2两个神器,在Mac os x下是一定要装的. 两组配合起来使用,加上插件。简直是神一样的存在。 秒杀梅西,内马尔啊:)
安装 oh my zsh
代码如下:
设置默认shell
查看系统支持的shell列表,Mac 10.9.4 自带了 zsh 5.0.2,Linux上得安装。
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
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常用命令:
代码如下:PHP #查找所有和PHP相关的应用
brew cask list #列出所有通过cask安装的软件
brew cask info PHPstorm #查看 PHPstorm 的信息
brew cask uninstall qq #卸载 QQ
这里谈谈cask对比Mac App Store的优势:
对常用软件支持更全面(特别是开发者),cask里面会给你一些惊喜;
软件更新速度快,一般都是最新版本 Store上很久很久才会更新版本;
命令安装感觉比打开Store方便,另外Store在国内的速度也是XXOO。
iTerm2@H_301_18@
安装iTerm2:
brew cask install iterm2
上面提过的神器组合,更多使用方法请参考[iTerm2官方文档](
n), 这里就不详细说明了。
安装开发常用的包&软件
安装开发包
代码如下:
升级一下系统自带的vim
代码如下:
安装常用软件@H_301_18@
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@H_301_18@
前面做了这么多的准备工作,其实 zsh iTerm2 brew 等等这些由于篇幅以及能力有限,一时半会也讲不完,更多选择,更多欢乐,就在Google
search,现在才入正题。come on :)
安装MysqL@H_301_18@
代码如下:MysqL
MysqL开机启动:
代码如下:MysqL/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.MysqL.plist
安装完成之后开启MysqL安全机制:
代码如下:MysqL/bin/MysqL_secure_installation
根据终端提示,输入root密码,然后依次确认一些安全选项。具体信息可以参考
查看一下MySQL运行情况
测试连接MySQL
mysql -uroot -p
Welcome to the MySQL monitor. Commands end with ; 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
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
安装phpmyadmin
代码如下:PHPmyadmin
安装PHP
代码如下:PHP
可以使用brew options PHP55命令来查看安装PHP5.5的选项,这里我用下面的选项安装:
代码如下:
PHP编译过程中如果遇到configure: error: Cannot find OpenSSL's 错误,执行xcode-select --install 重新安装一下Xcode Command Line Tools 在GitHubHomeBrew上有关于这个讨论:
_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扩展:
代码如下: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\ PHP55-xdebug;
扩展里面提一下 和.一个是C语言写的PHP框架,安装来个人摸索熟悉一下,还没有真正的使用过,大致看了一下文档,感觉非常吊炸天。目前公司的项目是基于Yii2的,也看看这个框架。
由于Mac自带了php和php-fpm,因此需要添加系统环境变量PATH来替代自带PHP版本。
代码如下:> ~/.bash_profile #for PHP
echo 'export PATH="$(brew --prefix PHP55)/sbin:$PATH"' >> ~/.bash_profile #for PHP-fpm
echo 'export PATH="/usr/local/bin:/usr/local/sbib:$PATH"' >> ~/.bash_profile #for other brew install soft
source ~/.bash_profile
测试一下效果:
代码如下:PHP 他在/usr/local/opt/PHP55/bin/PHP
PHP -v
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
Mac自带的PHP
/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
brew安装的PHP-fpm 他在/usr/local/opt/PHP55/sbin/PHP-fpm
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,by Derick Rethans
Mac自带的PHP-fpm
/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/<a href="https://www.jb51.cc/tag/PHP/" target="_blank" class="keywords">PHP</a>-fpm.pid
重启PHP-fpm
kill -USR2 cat /usr/local/var/run/<a href="https://www.jb51.cc/tag/PHP/" target="_blank" class="keywords">PHP</a>-fpm.pid
也可以用上文提到的brew命令来重启PHP-fpm,不过他官方不推荐用这个命令了
brew services restart PHP55
还可以用这个命令来启动PHP-fpm
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.PHP55.plist
启动PHP-fpm之后,确保它正常运行监听9000端口:
代码如下:PHP
PHP-fpm 30907 calvin 9u IPv4 0xf11f9e8e8033a2a7 0t0 TCP 127.0.0.1:9000 (LISTEN)
PHP-fpm 30917 calvin 0u IPv4 0xf11f9e8e8033a2a7 0t0 TCP 127.0.0.1:9000 (LISTEN)
PHP-fpm 30918 calvin 0u IPv4 0xf11f9e8e8033a2a7 0t0 TCP 127.0.0.1:9000 (LISTEN)
PHP-fpm 30919 calvin 0u IPv4 0xf11f9e8e8033a2a7 0t0 TCP 127.0.0.1:9000 (LISTEN)
#正常情况,会看到上面这些进程
PHP-FPM开机启动:
代码如下:PHP55/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.PHP55.plist
安装PHP composer
redis memcached这些软件brew 已经自动依赖安装上,如果想开机自动启动,或者查看使用说明 brew info redis即可。另外,composer的中文文档:猛戳这里
安装Nginx@H_301_18@
brew install Nginx --with-http_geoip_module
Nginx启动关闭命令:
代码如下:错误
Nginx -t
#重新加载配置|重启|停止|退出 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开机启动
代码如下:Nginx/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.Nginx.plist
Nginx监听80端口需要root权限执行,因此:
代码如下:
配置Nginx.conf
创建需要用到的目录:
代码如下: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
输入以下内容:
代码如下:
error_log /usr/local/var/logs/Nginx/error.log debug;
pid /usr/local/var/run/Nginx.pid;
events {
worker_connections 256;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$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.log main;
sendfile on;
keepalive_timeout 65;
port_in_redirect off;
include /usr/local/etc/Nginx/sites-enabled/*;
}
设置Nginx PHP-fpm配置文件
代码如下:Nginx/conf.d/PHP-fpm
#proxy the PHP scripts to PHP-fpm
location ~ \.PHP$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_intercept_errors on;
include /usr/local/etc/Nginx/fastcgi.conf;
}
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
输入:
代码如下:
access_log /usr/local/var/logs/Nginx/default.access.log main;
location / {
index index.html index.htm index.PHP;
autoindex on;
include /usr/local/etc/Nginx/conf.d/PHP-fpm;
}
location = /info {
allow 127.0.0.1;
deny all;
rewrite (.*) /.info.PHP;
}
创建ssl默认虚拟主机default-ssl
vim /usr/local/etc/Nginx/sites-available/default-ssl
输入:
代码如下:Nginx/default-ssl.access.log main; ssl on;
ssl_certificate ssl/localhost.crt;
ssl_certificate_key ssl/localhost.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
include /usr/local/etc/Nginx/conf.d/PHP-fpm;
}
location = /info {
allow 127.0.0.1;
deny all;
rewrite (.*) /.info.PHP;
}
error_page 404 /404.html;
error_page 403 /403.html;
}
创建PHPmyadmin虚拟主机
vim /usr/local/etc/Nginx/sites-available/PHPmyadmin
输入以下配置
代码如下:PHPmyadmin;
error_log /usr/local/var/logs/Nginx/PHPmyadmin.error.log; access_log /usr/local/var/logs/Nginx/PHPmyadmin.access.log main; ssl on;
ssl_certificate ssl/PHPmyadmin.crt;
ssl_certificate_key ssl/PHPmyadmin.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm index.PHP;
include /usr/local/etc/Nginx/conf.d/PHP-fpm;
} }
设置SSL
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 :)
参考资料:nofollow" target="_blank" href="http://blog.frd.mn/install-Nginx-PHP-fpm-MysqL-and-PHPmyadmin-on-os-x-mavericks-using-homebrew/">Install Nginx,PHP-FPM,MysqL and PHPMyAdmin on OS X Mavericks using Homebrew
本文由Fish创作
原文链接:https://www.f2er.com/php/20407.html
猜你在找的PHP相关文章
安装完成之后,建议执行一下自检,brew doctor如果看到 Your system is ready tobrew.那么你的brew已经可以开始使用了。
安装:
注意:brew services 相关命令最好别经常用了,提示会被移除
Stopping `PHP55`... (might take a while) ==> Successfully stopped `PHP55` (label: homebrew.mxcl.PHP55) ==> Successfully started `PHP55` (label: homebrew.mxcl.PHP55)
Oh My Zsh ohmyzsh & iTerm2两个神器,在Mac os x下是一定要装的. 两组配合起来使用,加上插件。简直是神一样的存在。 秒杀梅西,内马尔啊:)
安装 oh my zsh
设置默认shell
查看系统支持的shell列表,Mac 10.9.4 自带了 zsh 5.0.2,Linux上得安装。
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
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常用命令:
这里谈谈cask对比Mac App Store的优势:
对常用软件支持更全面(特别是开发者),cask里面会给你一些惊喜; 软件更新速度快,一般都是最新版本 Store上很久很久才会更新版本;
命令安装感觉比打开Store方便,另外Store在国内的速度也是XXOO。
iTerm2@H_301_18@
安装iTerm2:
brew cask install iterm2 上面提过的神器组合,更多使用方法请参考[iTerm2官方文档]( n), 这里就不详细说明了。
安装开发常用的包&软件 安装开发包
安装常用软件@H_301_18@
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@H_301_18@
前面做了这么多的准备工作,其实 zsh iTerm2 brew 等等这些由于篇幅以及能力有限,一时半会也讲不完,更多选择,更多欢乐,就在Google search,现在才入正题。come on :)
安装MysqL@H_301_18@
MysqL开机启动:
安装完成之后开启MysqL安全机制:
根据终端提示,输入root密码,然后依次确认一些安全选项。具体信息可以参考
查看一下MySQL运行情况
mysql -uroot -p
Welcome to the MySQL monitor. Commands end with ; 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
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
安装phpmyadmin
PHP编译过程中如果遇到configure: error: Cannot find OpenSSL's
_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扩展:
扩展里面提一下 和.一个是C语言写的PHP框架,安装来个人摸索熟悉一下,还没有真正的使用过,大致看了一下文档,感觉非常吊炸天。目前公司的项目是基于Yii2的,也看看这个框架。
由于Mac自带了php和php-fpm,因此需要添加系统环境变量PATH来替代自带PHP版本。
测试一下效果:
Mac自带的PHP
/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
brew安装的PHP-fpm 他在/usr/local/opt/PHP55/sbin/PHP-fpm
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,by Derick Rethans
Mac自带的PHP-fpm
/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 -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/<a href="https://www.jb51.cc/tag/PHP/" target="_blank" class="keywords">PHP</a>-fpm.pid
重启PHP-fpm
kill -USR2 cat /usr/local/var/run/<a href="https://www.jb51.cc/tag/PHP/" target="_blank" class="keywords">PHP</a>-fpm.pid
也可以用上文提到的brew命令来重启PHP-fpm,不过他官方不推荐用这个命令了
brew services restart PHP55
还可以用这个命令来启动PHP-fpm
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.PHP55.plist
启动PHP-fpm之后,确保它正常运行监听9000端口:
PHP-FPM开机启动:
安装Nginx@H_301_18@
brew install Nginx --with-http_geoip_module 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开机启动
vim /usr/local/etc/Nginx/Nginx.conf
输入以下内容:
error_log /usr/local/var/logs/Nginx/error.log debug;
pid /usr/local/var/run/Nginx.pid;
events { worker_connections 256; }
http { include mime.types; default_type application/octet-stream;
log_format main '$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.log main;
sendfile on; keepalive_timeout 65; port_in_redirect off;
include /usr/local/etc/Nginx/sites-enabled/*; }
#创建 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
输入:
access_log /usr/local/var/logs/Nginx/default.access.log main;
location / { index index.html index.htm index.PHP; autoindex on; include /usr/local/etc/Nginx/conf.d/PHP-fpm; }
location = /info { allow 127.0.0.1; deny all; rewrite (.*) /.info.PHP; }
vim /usr/local/etc/Nginx/sites-available/default-ssl
输入:
vim /usr/local/etc/Nginx/sites-available/PHPmyadmin 输入以下配置
设置SSL
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 接下来你可以通过下面这些连接访问:
设置快捷服务控制命令
为了后面管理方便,将命令 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 :)
参考资料:nofollow" target="_blank" href="http://blog.frd.mn/install-Nginx-PHP-fpm-MysqL-and-PHPmyadmin-on-os-x-mavericks-using-homebrew/">Install Nginx,PHP-FPM,MysqL and PHPMyAdmin on OS X Mavericks using Homebrew
本文由Fish创作
原文链接:https://www.f2er.com/php/20407.html