Mac搭建LNMP碰着笔记,MAC利用brew命令安装PHP7景况的章程

用了一年的Mac OS
X了,此前不熟知那个体系,用的是系统自带的PHP以及DMG包安装的MySQL,时间长了,慢慢感觉MacBook的速度跟不上了,纵然关机次数相当的少,可是每一次开机,恐怕提醒Computer的时候,系统分明有料定期间的卡顿。非常表现在开机的时候。完全能够去泡二个来一桶了。因而干掉MD101上的光驱,换上256G的Sandisk
SSD, 干掉原厂的2G 2,换上8G 2 。
速度相应是杠杠的了,至少能够再从军2年呢。
趁着这一次加硬盘的火候,就筹算深透重做开采条件。未来对Mac也可以有了自然的打听,特地记录一下此番的付出条件设置详细的情况,给本身三个备忘,希望也得以支持到刚接触Mac
碰到的同室们。本开荒遭遇,全体基于HomeBrew安装。
驷不及舌软件版本:PHP5.5.14,Nginx 1.6.0,MySQL5.6.19

安装Homebrew

近年几年平昔在LNMP景况下开始展览支付,当中的PHP依然5.5本子,有一点老旧,二零一八年10月PHP7已经正式公布,新添了一些语法本性,最大的优点是性质的升官,所以平素想提高到PHP7,由于时日涉及一贯拖到以往。到写本文截至PHP最新版本为:7.0.9的stable,所以牢固性上基本不用操心。

Brew

brew的设置格局如下:

ruby -e “$(curl -fsSL
)”

brew常用选项

brew install xxx

brew uninstall xxx

brew list

brew update xxx

OS X Mavericks
重新安装系统,在苹果商场下载好OS X
Mavericks安装文件,然后计划一支16G的USB3.0 U盘。制作 OSX
Mavericks全新安装运维U盘。

确定保证系统现已设置xcode,然后利用一行命令安装依赖管理工科具 Homebrew
ruby -e “$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/master/install)”

前面写的 MAC下安装LNMP境况 是用brew安装的,此次晋级PHP7继续应用brew,
安装/晋级软件很平价。

Nginx

运用Nginx也相比方便,首先安装

brew install nginx

使用80端口,需要将nginx加入root组当中:

暗许目录,依据实际版本号填写

sudo chown root:wheel /usr/local/Cellar/nginx/1.12.1/bin/nginx

sudo chmod u+s /usr/local/Cellar/nginx/1.12.1/bin/nginx

nginx配置

nginx.conf文件配置

cd /usr/local/etc/nginx/

vi nginx.conf

worker_processes  1;

error_log  /usr/local/var/log/nginx/error.log debug;

events {

worker_connections  1024;

}

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/log/nginx/access.log  main;

sendfile            on;

keepalive_timeout  65;

index index.html index.php;

include /usr/local/etc/nginx/servers/*.conf;

}

nginx目录下新建conf.d文件夹

mkdir /usr/local/etc/nginx/conf.d

conf.d里新建php-fpm配置

location ~ \.php$ {

try_files      $uri = 404;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME
$document_root$fastcgi_script_name;

include        fastcgi_params;

}

servers文件夹里配置站点文件

server {

listen      80;

server_name  work.love;

root        /Users/admin/works/blog/public/;

access_log  /usr/local/var/log/nginx/host.access.log  main;

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;

}

投入launchctl运行调节

mkdir -p ~/Library/LaunchAgents

cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist
~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

到那边,nginx基本上是完工了

运行nginx :

sudo nginx #打开 nginx

nginx -s reload|reopen|stop|quit  #重复加载配置|重启|甘休|退出 nginx

nginx -t  #测量试验配置是还是不是有语法错误


插上U盘,在终极施行:

尔后就能够利用
brew install FORMULA

升级brew

php

php 的安装相对nginx和mysql来讲,要复杂点,因为brew 私下认可未有php的包

brew tap homebrew/dupes

brew tap homebrew/versions

brew tap homebrew/homebrew-php

关闭老版本的PHP进度

brew unlink php56

施行完上边命令后,那年才方可设置php,可是php有广大的版本,你能够用:

brew search php

来查阅具体的本子

始发安装PHP7

brew install php71

开启PHP71进程

brew link php71

输入指令,查看是不是中标

php -v

增添系统意况变量PATH来便于大家的运用

进去配置文件

sudo vim ~/.bash_profile

修改暗中同意PHP版本

export PATH=”$(brew –prefix php71)/bin:$PATH”

export PATH=”$(brew –prefix php71)/sbin:$PATH”

export PATH=”/usr/local/bin:/usr/local/sbin:$PATH”

终点运营

source ~/.bash_profile

细心:  如若您用的是zsh,那么您投入的安插文件是

~/.zshrc

配置php-fpm,修改php-fpm.conf文件

/usr/local/etc/php/7.1/php-fpm.conf

;pid = run/php-fpm.log

;error_log = log/php-fpm.log

修改为

pid = /usr/local/var/run/php-fpm.pid

error_log = /usr/local/var/log/php-fpm.log

启动php-fpm

sudo /usr/local/Cellar/php71/7.1.8_20/sbin/php-fpm -D

停止php-fpm

sudo killall php-fpm

安装扩大memcached

brew install php71-memcached

陈设文件

/usr/local/etc/php/7.0/conf.d/ext-memcached.ini

设置扩大redis

brew install php71-redis

铺排文件

/usr/local/etc/php/7.0/conf.d/ext-redis.ini

越多扩展通过以下命令找出

brew search php

开始展览安装

brew install 扩展名

安装php-fpm的开机自运行

mkdir -p ~/Library/LaunchAgents

cp /usr/local/opt/php71/homebrew.mxcl.php71.plist
~/Library/LaunchAgents/

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist

输入指令查看php-fpm是还是不是运转

lsof -Pni4|grep LISTEN | grep php

php版本

php -v

~/usr/local/opt/php71/bin/ -v

php-fpm版本

php-fpm -v

~/usr/local/opt/php71/sbin/php-fpm -v

陈设文件

安装好后变化的配置文件都在 /usr/local/etc/php/7.0 目录里,分别如下:

php.ini

/usr/local/etc/php/7.1/php.ini

php-fpm.conf

/usr/local/etc/php/7.1/php-fpm.conf

php, phpize, php-config

ls /usr/local/opt/php71/bin

php-fpm

/usr/local/opt/php71/sbin/php-fpm


复制代码 代码如下:

来安装所要求的重视了。
brew(意为酿酒)的命名很有趣,全部都应用了酿酒进度中运用的材质/器械,名词对应以下的概念:
Mac搭建LNMP碰着笔记,MAC利用brew命令安装PHP7景况的章程。Formula(配方) 程序包定义,本质上是一个rb文件
Keg(桶)程序包的装置路径
Cellar(地窖)全部程序包(桶)的根目录
Tap(水阀)程序包的源
Bottle (双鱼瓶)编写翻译打包好的次序包
终极编写翻译安装收尾的顺序就是一桶酿制好的酒
更详细的音讯参谋 Homebrew的合法Cookbook
于是选用Homebrew常见的流程是:

brew update
配置

mysql

官方网站下载mac安装包安装

安装完结后终端命令

vi ~/.bash_profile

加上以下变量

PATH=$PATH:/usr/local/mysql/bin

Mac 下安装MySQL后, shell不可能识别MySQL命令

MySQL -V

shell显示 command not found: mysql

案由是自身用的zsh  输入以下命令完美消除

vi ~/.zshrc  插入  source ~/.bash_profile

终点实施 

source ~/.zshrc

为了方便使用,大家常常会制造猖狂连接的root用户:

GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ IDENTIFIED BY
‘MyNewPass4!’ WITH GRANT OPTION;

刷新权限职务令生效:

flush privileges;

“`

sudo /Applications/Install\ OS\ X\
Mavericks.app/Contents/Resources/createinstallmedia –volume
/Volumes/untitled
–applicationpath /Applications/Install\ OS\ X\ Mavericks.app
–nointeraction

  1. 充实多少个程序源(新增添一个水阀) brew tap homebrew/php
  2. 履新程序源 brew update
  3. 安装程序包(依照配方酿酒) brew install git
  4. 查看配置 brew config 可以看来程序包默许安装在 /usr/local/Cellar 下
    (酒桶放在地窖内)
    安装PHP5.6(FPM方式)
    首先步向Homebrew官方的多少个软件源
    brew tap homebrew/dupes
    brew tap homebrew/versions
    brew tap homebrew/php

brew tap homebrew/dupes
brew tap homebrew/versions 
brew tap homebrew/homebrew-php
安装PHP7

untitled 是您的u盘盘符,依据实际意况来。

PHP即使运用暗中同意配置安装,会编写翻译 mod_php
模块并只运转在Apache境况下,为了利用Nginx,这里须求编写翻译php-fpm并且禁止使用apache,首要透过参数
–without-snmp –without-apache 来完成。完整的装置指令为
brew install php56
–without-snmp
–without-apache
–with-debug
–with-fpm
–with-intl
–with-homebrew-curl
–with-homebrew-libxslt
–with-homebrew-openssl
–with-imap
–with-mysql
–with-tidy

brew install php70
境遇的标题

复制代码 代码如下:

是因为OSX已经自带了PHP境遇,因而要求修改系统路线,优先运营brew安装的本子,在
~/.bashrc 里加入:
export PATH=”/usr/local/bin:/usr/local/sbin:$PATH”

设置提醒:

Erasing Disk: 0%… 10%… 20%… 30%…100%…
>Copying installer files to disk…
Copy complete.
Making disk bootable…
Copying boot files…
>Copy complete.
>Done.

假诺要设置新的php扩张,能够直接设置而不用每一回重复编写翻译php,全部的恢宏能够由此
brew search php56

➜  ~ brew install php70
==> Installing php70 from homebrew/php
Error: Cannot install homebrew/php/php70 because conflicting formulae
are installed.

见到上边的新闻表明运转盘制作成功。 安装起来so easy :)

看到,下边是本身要好所急需的扩大,可以支撑 Phalcon框架 :
brew install php56-gearman php56-msgpack php56-memcache php56-memcached
php56-mongo php56-phalcon php56-redis php56-xdebug

  php55: because different php versions install the same binaries.

安装落成系统之后,
一时还从未去迁移文件,由于自身喜爱水墨画,有大量RAW格式的原图在Aperture
的照片库中,NikonD800一张RAW文件有40M左右,到时候迁移照片库和相片流希望不用掉坑里了。
等开销情形消除再说了,更新OS X系统到10.9.4
,然后安装新型的Xcode,
以及在公司买过的软件。鲜明系统无难点了,进入下一步…

PHP-FPM的加载与开发银行
设置收尾后得以经过以下指令运转和停歇php-fpm
php-fpm -D
killall php-fpm

Please `brew unlink php55` before continuing.

Brew
Brew 是 Mac 上面的包管理工科具,通过 Github 托管适合 Mac 的编写翻译配置以及
Patch,能够方便的装置开采工具。 Mac 自带ruby
据此安装起来非常的低价,同期它也会自行把git也给您装上。官网:
<;; 。

同一时间能够讲php-fpm到场开机运营
ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

Unlinking removes a formula’s symlinks from /usr/local. You can
link the formula again after the install finishes. You can –force
this
install, but the build may fail or cause obscure side-effects in the
resulting software.
依照提醒实践: brew unlink php55
后续设置: brew install php70

设置到位之后,建议实行一下自检,brew doctor即使见到
Your system is ready tobrew.那么你的brew已经可以初始应用了。

安装Nginx
brew install nginx

布署文件

安装:

安装完结后得以经过
nginx
nginx -s quit

设置好后变化的布局文件都在 /usr/local/etc/php/7.0 目录里,分别如下:

复制代码 代码如下:

开行和倒闭,同期也支撑重载配置文件等操作
nginx -s reload|reopen|stop|quit

php.ini /usr/local/etc/php/7.0/php.ini
php-fpm.conf /usr/local/etc/php/7.0/php-fpm.conf
php, phpize, php-config ls /usr/local/opt/php70/bin
php-fpm /usr/local/opt/php70/sbin/php-fpm

ruby -e “$(curl -fsSL
)”

nginx安装后默许监听8080端口,能够访谈
http://localhost:8080
查看景况。假使要想监听80端口必要root权限,运转
sudo chown root:wheel /usr/local/Cellar/nginx/1.6.2/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.6.2/bin/nginx

加盟开机运转

自检:

并采取root权限运转
sudo nginx

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php70/homebrew.mxcl.php70.plist
~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
命令行配置

复制代码 代码如下:

开机运行
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

vim ~/.zshrc

export PATH=”$(brew –prefix php55)/bin:$PATH”
替换为
export PATH=”$(brew –prefix homebrew/php/php70)/bin:$PATH”

brew doctor

Nginx + PHP-FPM配置
Nginx一般都会运转多个域名,由此这里仿照效法了 @fish的方法
,按Ubuntu的文件夹结构来寄放Nginx的安插文件
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

alias php-fpm.start=”launchctl load -w
~/Library/LaunchAgents/homebrew.mxcl.php55.plist”
alias php-fpm.stop=”launchctl unload -w
~/Library/LaunchAgents/homebrew.mxcl.php5.plist”
alias php-fpm.restart=’php-fpm.stop && php-fpm.start’
修改为

常用命令: (全体软件以PHP5.5为例子)

编辑Nginx全局配置
vim /usr/local/etc/nginx/nginx.conf

alias php-fpm.start=”launchctl load -w
~/Library/LaunchAgents/homebrew.mxcl.php70.plist”
alias php-fpm.stop=”launchctl unload -w
~/Library/LaunchAgents/homebrew.mxcl.php70.plist”
alias php-fpm.restart=’php-fpm.stop && php-fpm.start’
重复加载配置文件

复制代码 代码如下:

worker_processes 1;
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” $host $request_time
$upstream_response_time $scheme ‘
‘$cookie_evalogin’;
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/*;
}

source ~/.zshrc
证实版本

brew update #更新brew可安装包,建议每一遍实行一下
brew search php55 #搜索php5.5
brew tap josegonzalez/php #设置扩大<gihhub_user/repo>
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

那样一来首先能够把一些可复用配置独立出来放在/usr/local/etc/nginx/conf.d
下,比方fastcgi的装置就能够单独出来
vim /usr/local/etc/nginx/conf.d/php-fpm

PHP版本

只顾:brew services 相关命令最棒别平日用了,提醒会被移除

内容为
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;
}

➜  ~ /usr/local/opt/php70/bin/php -v
PHP 7.0.9 (cli) (built: Jul 21 2016 14:50:47) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
php-fpm版本

复制代码 代码如下:

下一场 /usr/local/etc/nginx/sites-enabled
目录下能够一个文书对应三个域名的布局,比如web服务器目录是 /opt/htdocs
vim /usr/local/etc/nginx/sites-enabled/default

➜  ~ /usr/local/opt/php70/sbin/php-fpm -v
PHP 7.0.9 (fpm-fcgi) (built: Jul 21 2016 14:50:51)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
启动PHP-FPM

~ 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.

server {
listen 80;
server_name localhost;
root /opt/htdocs/;
location / {
index index.html index.htm index.php;
include /usr/local/etc/nginx/conf.d/php-fpm;
}
}

执行: php-fpm.start

Stopping `php55`… (might take a while)
==> Successfully stopped `php55` (label: homebrew.mxcl.php55)
==> Successfully started `php55` (label: homebrew.mxcl.php55)

那儿运维了php-fpm并且运营了Nginx后,就足以经过
http://localhost
来运行php程序了
安装MySQL
brew install mysql

反省是否运行成功:

Oh My Zsh
ohmyzsh & iTerm2三个神器,在Mac os x下是迟早要装的.
两组同盟起来使用,加上插件。简直是神同样的存在。
秒杀Messi,Neymar啊:)
Oh 猛戳到官方网站

能够经过
mysql.server start
mysql.server stop

➜  ~ ps aux|grep php-fpm
qloog           60380   0.2  0.0  2432792    604 s001  R+    6:00PM  
0:00.00 grep –color=auto –exclude-dir=.bzr –exclude-dir=CVS
–exclude-dir=.git –exclude-dir=.hg –exclude-dir=.svn php-fpm
qloog           60378   0.0  0.0  2473348    620   ??  S     6:00PM  
0:00.00 /usr/local/opt/php70/sbin/php-fpm –fpm-config
/usr/local/etc/php/7.0/php-fpm.conf
qloog           60377   0.0  0.0  2473348    648   ??  S     6:00PM  
0:00.00 /usr/local/opt/php70/sbin/php-fpm –fpm-config
/usr/local/etc/php/7.0/php-fpm.conf
qloog           60372   0.0  0.0  2475396   7844   ??  S     6:00PM  
0:00.03 /usr/local/opt/php70/sbin/php-fpm –fpm-config
/usr/local/etc/php/7.0/php-fpm.conf
安装增加

安装 oh my zsh

来运营/甘休,运维后私下认可应该为空密码,能够经过mysqladmin设置三个密码
mysqladmin -uroot password “mypassword”

yaf

复制代码 代码如下:

可是在操作的时候出现了空密码不大概登录的气象,最终不得不通过mysqld_safe来设置
sudo mysqld_safe –skip-grant-tables
mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD(‘mypassword’) WHERE
User=’root’;
mysql> FLUSH PRIVILEGES;

brew install php70-yaf

curl -L | sh

末段将MySQL插足开机运营
cp /usr/local/Cellar/mysql/5.6.22/homebrew.mxcl.mysql.plist
~/Library/LaunchAgents/

布局文件
/usr/local/etc/php/7.0/conf.d/ext-yaf.ini

设置暗中同意shell

Memcache
brew install memcached

memcached

翻看系统援救的shell列表,Mac 10.9.4 自带了 zsh 5.0.2,Linux上得安装。

启航/甘休指令
memcached -d
killall memcached

brew install php70-memcached

cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/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 

插手开机运行
cp /usr/local/Cellar/memcached/1.4.20/homebrew.mxcl.memcached.plist
~/Library/LaunchAgents/

安顿文件
/usr/local/etc/php/7.0/conf.d/ext-memcached.ini

虽说Mac自带了zsh,假使您想要最新版的zsh,那么你用 brew install
zsh安装三个流行的啊。

Redis
brew install redis

redis

/usr/local/bin/zsh –version zsh 5.0.5 (x86_64-apple-darwin13.3.0)
差别也不会比非常的大, 私下认可的版本已经很新了。
homebrew-cask

Redis暗许配置文件不允许以Deamon格局运转,因而供给先修改配置文件
vim /usr/local/etc/redis.conf

brew install php70-redis

安装cask:

将daemonize修改为yes,然后载入配置文件即可实现后台进程运维
redis-server /usr/local/etc/redis.conf

布署文件
/usr/local/etc/php/7.0/conf.d/ext-redis.ini

brew tap phinze/homebrew-cask && brew install brew-cask

步向开机运行
cp /usr/local/Cellar/redis/2.8.19/homebrew.mxcl.redis.plist
~/Library/LaunchAgents/

xdebug

cask常用命令:

设置小名
最后能够对富有服务的开发银行停止设置小名方便操作
vim ~/.bash_profile

brew install php70-xdebug

复制代码 代码如下:

加入
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’

铺排文件
/usr/local/etc/php/7.0/conf.d/ext-xdebug.ini

brew cask search #列出富有能够被设置的软件
brew cask search php #查找所有和php相关的应用
brew cask list #列出装有通过cask安装的软件
brew cask info phpstorm #查看 phpstorm 的信息
brew cask uninstall qq #卸载 QQ

设置任何品类支撑
·brew install composer node

swoole

此间谈谈cask相比Mac App Store的优势:

brew install php70-swoole

对常用软件帮忙更周到(极度是开垦者),cask里面会给您有的惊奇;
软件更新速度快,一般都以时尚版本 Store上比较久十分久才会更新版本;

配备文件
/usr/local/etc/php/7.0/conf.d/ext-swoole.ini

命令安装认为比张开Store方便,其余Store在境内的快慢也是XXOO。

愈来愈多扩张实践 brew install 扩张名 进行设置

iTerm2

安装iTerm2:

brew cask install iterm2
地方提过的神器组合,越来越多采取方式请参见[iTerm2官方文书档案](
n), 这里就不详细表达了。

安装开荒常用的包&软件
安装开垦包

复制代码 代码如下:

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`增加到AyrFred的搜寻目录

MySQL PHP Nginx Redis Memcache

前方做了如此多的预备工作,其实 zsh iTerm2 brew
等等这几个由于篇幅以及才具轻巧,有时半会也讲不完,越来越多采取,更加多开心,就在Google
search,今后才入正题。come on :)

安装MySQL

复制代码 代码如下:

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密码,然后每家每户确认一些有惊无险选项。具体音讯能够参见
海外朋友的这篇文章

翻开一下MySQL运转情状

 ~ ps aux | grep mysql
calvin   1695 0.0 0.5 2719864 90908 ?? S  1:38上午 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
calvin   1323 0.0 0.0 2444628 1020 ?? S  1:38上午 0:00.04 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --bind-address=127.0.0.1 --datadir=/usr/local/var/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

复制代码 代码如下:

brew install phpmyadmin

安装PHP

添加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 在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扩张:

复制代码 代码如下:

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\
php55-xdebug;

推而广之里面提一下php55-phalcon
和php55-swoole.二个是C语言写的PHP框架,安装来个人研究熟悉一下,还未曾当真的应用过,大致看了弹指间文书档案,感觉十一分吊炸天。近日集团的项目是基于Yii2的,也看看那几个框架。

除此以外三个swoole是国产的PHP高质量网络通讯框架,貌似准确,只怕在档案的次序中会思索接纳它。

出于Mac自带了php和php-fpm,由此须求增加系统景况变量PATH来顶替自带PHP版本。

复制代码 代码如下:

echo ‘export PATH=”$(brew –prefix php55)/bin:$PATH”‘ >>
~/.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

测验一下职能:

复制代码 代码如下:

#brew安装的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, 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-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/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之后,确认保证它不荒谬运转监听八千端口:

复制代码 代码如下:

lsof -Pni4 | grep LISTEN | grep 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开机运行:

复制代码 代码如下:

ln -sfv /usr/local/opt/php55/*.plist ~/Library/LaunchAgents launchctl
load ~/Library/LaunchAgents/homebrew.mxcl.php55.plist

安装php composer

复制代码 代码如下:

brew install composer
#检查一下情形
composer –version
Composer version 1.0.0-alpha8 2014-01-06 18:39:59

redis memcached那一个软件brew
已经自行依赖安装上,借使想开机自动运行,可能查看使用表达 brew info
redis就可以。其余,composer的国语文档:猛戳这里
安装Nginx

brew install nginx
–with-http_geoip_module
Nginx运维关闭命令:

复制代码 代码如下:

#测验配置是还是不是有语法错误
nginx -t

#打开 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 1;

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配置文件

复制代码 代码如下:

vim /usr/local/etc/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

输入:

复制代码 代码如下:

server {
listen 80;
server_name localhost;
root /var/www/;

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;
}

error_page 404 /404.html;
error_page 403 /403.html;
}

创立ssl暗中认可设想主机default-ssl

vim /usr/local/etc/nginx/sites-available/default-ssl

输入:

复制代码 代码如下:

server {
listen 443;
server_name localhost;
root /var/www/;
access_log /usr/local/var/logs/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
输入以下配置

复制代码 代码如下:

server {
listen 306;
server_name localhost;
root /usr/local/share/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 :)

参照他事他说加以考察资料:Install Nginx, PHP-FPM, MySQL and phpMyAdmin on OS X
Mavericks using
Homebrew

本文由Fish创作

你或者感兴趣的篇章:

  • mac下安装nginx和php
  • Mac下搭建php开拓条件教程
  • 在Mac上编写翻译安装PHP7的开采条件
  • Mac下php 5晋级到php
    7的步骤详解

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website