MAC OS brew安装MNMP

安装HomeBrew

BrewMac下面的包管理工具,就像centos下面的yum同样。HomeBrew能够经过ruby来安装,mac系统是自带ruby的,因此只要在终端运行下面的代码便可安装HomeBrewphp

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

在安装的时候会有下面的提示,你应该仔细看下,要清楚知道HomeBrew给你安装了哪些脚本,给你建立了哪些文件夹,路径是在哪里的。仔细的看下安装时出现的说明信息,这样即便没有用过的软件,你根本不用看文档,都是可以使用它的最基础功能的。若是你必定要研究下细致的,能够看HomeBrew的官网:http://brew.shhtml

==> This script will install:
/usr/local/bin/brew /usr/local/share/doc/homebrew /usr/local/share/man/man1/brew.1 /usr/local/share/zsh/site-functions/_brew /usr/local/etc/bash_completion.d/brew /usr/local/Homebrew ==> The following new directories will be created: /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var

如今咱们已经安装完HomeBrew了,其实你只要运行brew help就能知道该怎么用这个软件了。python

自检Brew

安装完成以后,建议执行一下自检,brew doctor若是看到Your system is ready to brew. 那么你的brew已经能够开始使用。mysql

美化下终端

brew咱们已经安装好了,如今已经可使用了,可是看上面的图,咱们的终端太他妈的丑了,mac默认使用的shell是bash,若是把它换成zsh,并安装zsh的插件oh-my-zsh,那就会好不少了,mac系统已经自带了zsh,咱们就不用去安装了,执行zsh --version能够查看zsh的版本,咱们须要安装个zsh的插件oh-my-zshnginx

安装oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

终端执行上面的代码便可,程序安装完oh-my-zsh后会自动帮咱们把shell切换为zsh,如今咱们的终端就变成这样了,注:oh-my-zsh还能够更换主题和装插件的,具体访问:http://ohmyz.shlaravel

安装FiraCode字体

嗯,上面的差很少了,咱们再安装个比较流行的编程字体FireCode,能够进入:https://github.com/tonsky/FiraCode点击下载,上面的地址可能会下载失败,我也把这个字体放在百度网盘上了。c++

如今咱们打开终端,点击终端->偏好设置,咱们在这里按本身的喜欢设置一下背景,字体,颜色,行间距等便可,我设置完就成为下面这样了,嗯,这样就好看多了git

安装终端的命令自动提示

在终端下操做会常常须要输入一些经常使用的命令,要不出错的输入这些命令也不是件容易的事,zsh还有一个很好用的补全命令的插件zsh-autosuggestions, 咱们经过下面命令安装下:github

brew install zsh-autosuggestions

我记得之前只要这么安装完就能够的,可是此次我安装完仍是没有出现自动提示,不去想这个缘由了,咱们本身设置下就好了,先找到zsh-autosuggestions.zsh文件的安装路径,在/usr/local/Cellar/zsh-autosuggestions/0.3.3/share/zsh-autosuggestions里面(这里就是前面我为何要你们看brew的安装提示了,咱们知道brew将程序安装在什么文件夹,那就很容易的找到咱们要的文件),咱们把zsh-autosuggestions.zsh放入~/.zshrc文件中,就是加入下面这句话:sql

source /usr/local/Cellar/zsh-autosuggestions/0.3.3/share/zsh-autosuggestions/zsh-autosuggestions.zsh

好了,而后你能够执行source ~/.zshrc或者从新打开终端。

 

使用homebrew-cask安装sublime

先安装cask, 使用cask能够安装一些应用程序,如QQ,迅雷,谷歌浏览器等,功能和App stroe差很少,我的以为这个更好管理

# 网上大部分方法都是用brew tap添加源再安装的,其实不用那么麻烦,只要输入brew cask便可,brew会自动帮咱们完成cask安装。 brew cask # 没有安装cask会自动安装,已经安装cask的,会跳出cask命令列表

Cask 经常使用命令

brew cask search        #列出全部能够被安装的软件 brew cask search sublime  #查找全部和sublime相关的应用 brew cask list #列出全部经过cask安装的软件 brew cask info sublime-text #查看 sublime 的信息 brew cask install sublime-text # 安装sublime brew cask uninstall sublime-text #卸载sublime

一般咱们是不知道软件的全称的,好比安装sublime,咱们能够先使用brew cask serach搜索:

brew cask search sublime
==> Exact match
caskroom/cask/sublime
==> Partial matches
caskroom/cask/sublime-text               caskroom/cask/sublime-text

从上面咱们能够看出,要安装的sublime全称是sublime-text,咱们使用brew cask install sublime-text来安装它

brew cask install sublime-text

给sublime换主题

先给sublime text 3安装Package Control, 按住control + ` ,在弹出的命令行输入:

import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

而后command + shift + p,打开Package Control,输入install,选择Package Control:Install Package回车,在跳出的命令行输入选择Material Theme安装

好了,而后鼠标移到菜单栏Sublime Text -> Preferences > Settings在右边的窗口(user)中输入你本身要的配置,个人配置以下:

{ "always_show_minimap_viewport": false, "color_scheme": "Packages/Material Theme/schemes/OLD/Material-Theme.tmTheme", "font_face": "Fira Code", "font_size": 15, "ignored_packages": [ "Vintage" ], "line_padding_bottom": 4, "line_padding_top": 4, "theme": "Material-Theme.sublime-theme", "translate_tabs_to_spaces": true, "tab_size": 4, }

安装Mysql

先查找下mysql

➜  ~ brew search mysql
automysqlbackup            mysql-cluster              mysql-sandbox
mysql                      mysql-connector-c          mysql-search-replace
mysql++                    mysql-connector-c++        mysqltuner
homebrew/php/php53-mysqlnd_ms            homebrew/versions/mysql56
homebrew/php/php54-mysqlnd_ms            Caskroom/cask/mysql-connector-python
homebrew/php/php55-mysqlnd_ms            Caskroom/cask/mysqlworkbench
homebrew/php/php56-mysqlnd_ms            Caskroom/cask/navicat-for-mysql
homebrew/versions/mysql55                Caskroom/cask/sqlpro-for-mysql

看一下mysql的版本信息

➜  ~ brew info mysql   
mysql: stable 5.7.16 (bottled)
Open source relational database management system # 下面信息省略

下面就用brew install mysql安装下吧,安装时的消息有这么一句话We've installed your MySQL database without a root password. To secure it run:mysql_secure_installation,那就来设置下root的密码

# 第一步:打开mysql服务 mysql.server start # 第二步:执行mysql_secure_installation mysql_secure_installation # 执行后按照提示信息进行设置,慢慢看下英文,都能看懂的

好了,进入mysql看下

 ~ mysql -u root -p        
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.16 Homebrew

Copyright (c) 2000, 2016, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> 

安装php

直接brew search php 没有用,你能够试下看看提示信息,要先添加php扩展

brew update # 安装软件前都要习惯的更新下brew源 brew tap homebrew/dupes brew tap josegonzalez/homebrew-php

如今brew search php就能够了,出来一堆版本的php,咱们就安装php7.0版本吧,我用php7.1版本在跑laravel的时候,出现过错误,我那时候没有解决掉,装回php7.0没有问题。

能够先brew options ph70看看你安装的时候要哪些选项,我选择了下面这些,由于后面咱们会用nginx做为反向代理,因此就不要用--with-apache选项了,也不要添加--without-fpm选项

brew install php70 --with-debug --with-gmp --with-homebrew-curl --with-homebrew-libressl --with-homebrew-libxml2 --with-homebrew-libxslt --with-imap --with-libmysql --with-mssql

因为Mac自带了php和php-fpm,所以须要添加系统环境变量PATH来替代自带PHP版本,咱们用的是zsh,因此放进.zshrc中,若是你用的shell是bash,那么能够把下面的信息写入到~/.bash_profile文件中,若是这个文件没有,你本身建一个就行。

echo 'export PATH="$(brew --prefix php70)/bin:$PATH"' >> ~/.zshrc #for php echo 'export PATH="$(brew --prefix php70)/sbin:$PATH"' >> ~/.zshrc #for php-fpm echo 'export PATH="/usr/local/bin:/usr/local/sbib:$PATH"' >> ~/.zshrc #for other brew install soft source ~/.zshrc

测试下效果

# brew安装的php ➜ ~ php -v  PHP 7.0.12 (cli) (built: Oct 24 2016 00:06:38) ( NTS DEBUG ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies # brew安装的php-fpm ➜ ~ php-fpm -v PHP 7.0.12 (fpm-fcgi) (built: Oct 24 2016 00:06:45) (DEBUG) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies # Mac自带的php, 我之前的项目有些依赖不支持php7,因此这个我是留着的,随时切换使用 ➜ ~ /usr/bin/php -v  PHP 5.6.24 (cli) (built: Aug 8 2016 16:58:37) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies # Mac自带php-fpm ➜ ~ /usr/sbin/php-fpm -v PHP 5.6.24 (fpm-fcgi) (built: Aug 8 2016 16:58:54) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies ➜ ~ 

下面先来看下php-fpm的配置文件,路径在/usr/local/etc/php/7.0/php-fpm.conf, 你们应该都猜的到。咱们主要看下pid和log文件会放在哪里

13 [global]
 14 ; Pid file
 15 ; Note: the default prefix is /usr/local/var 16 ; Default Value: none 17 ;pid = run/php-fpm.pid 18 19 ; Error log file 20 ; If it's set to "syslog", log is sent to syslogd instead of being written 21 ; in a local file. 22 ; Note: the default prefix is /usr/local/var 23 ; Default Value: log/php-fpm.log 24 ;error_log = log/php-fpm.log

本身看下上面的信息,去掉17行和24行前面的分号,使用php-fpm -t测试下配置是否正确,按提示信息是无论它也能够,默认就是在/usr/local/var路径下的,不过仍是设置下吧;

➜  7.0 php-fpm -t
[24-Oct-2016 11:20:31] NOTICE: configuration file /usr/local/etc/php/7.0/php-fpm.conf test is successful

php-fpm的一些管理:

#测试php-fpm配置 php-fpm -t #启动php-fpm php-fpm -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 start|stop|restart php70 #还能够用这个命令来管理php-fpm php70-fpm start|stop|restart 

启动php-fpm以后,确保它正常运行监听9000端口:

➜  ~ lsof -Pni4 | grep LISTEN | grep php
php-fpm   18381  zjp    8u  IPv4 0xbca78421d968b30f      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   18382  zjp    0u  IPv4 0xbca78421d968b30f      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   18383  zjp    0u  IPv4 0xbca78421d968b30f      0t0  TCP 127.0.0.1:9000 (LISTEN)

安装Nginx

和前面同样先brew search nginx查找nginx, 看下信息brew info nginx
而后安装brew install nginx

安装信息记录下,用的到:

➜  ~ brew install nginx
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
gitless
==> Updated Formulae
fzf                                                                                    gammu

==> Downloading https://homebrew.bintray.com/bottles/nginx-1.10.2.sierra.bottle.tar.gz
######################################################################## 100.0% ==> Pouring nginx-1.10.2.sierra.bottle.tar.gz ==> Using the sandbox ==> Caveats Docroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. nginx will load all files in /usr/local/etc/nginx/servers/. To have launchd start nginx now and restart at login: brew services start nginx Or, if you don't want/need a background service you can just run: nginx ==> Summary

Nginx启动关闭命令:

#测试配置是否有语法错误 nginx -t #打开 nginx sudo nginx #从新加载配置|重启|中止|退出 nginx nginx -s reload|reopen|stop|quit
好了,来跑下nginx
sudo nginx

到这里为止,咱们已经安装完了mysql php nginx, 在安装php的时候添加了--with-mysql, 因此php操做mysql是没有问题的,如今咱们就要配置nginx,让它监听php-fpm的进程,这样当用户打开浏览器访问的时候,身为反向代理的nignx就能把东西让php去执行了。

接下来,咱们要配置nginx.conf文件,建立一个php-fpm文件(监听php-fpm), 还要约定下将nginx.pid文件,log日志,以及之后咱们要配置的站点.conf的路径,咱们的路径约定仍是按照brew默认的目录来设置,以下:

# nginx.conf,已经被建立好了,咱们一会要更改下 /usr/local/etc/nginx/nginx.conf # php-fpm,这个咱们就放在和nginx.conf同样的路径下吧,这个要咱们本身建立 /usr/local/etc/nginx/php-fpm # 日志文件放在/usr/local/var/log/nginx中,默认已经有了access.log和error.log文件了 /usr/local/var/log/nginx/ # nginx.pid文件,放在/usr/local/var/run/下面,和php-fpm.pid放一堆 /usr/local/var/run/  # 之后要配置的站点.conf, 咱们就放在/usr/local/etc/nginx/servers/下面,这个servers文件夹自己就存在的 /usr/local/etc/nginx/servers/ # 站点的根目录,也就用brew给咱们设置的吧 /usr/local/var/www/

我不知道你们是怎么来定义路径的,个人智商不咋的,记性很是的差,通常我都用brew安装软件,因此用brew默认的路径,我能方便的找到个人文件。

下面咱们先来修改nginx.conf, 用vim打开,把下面的信息覆盖nginx.conf, vim /usr/local/etc/nginx/nginx.conf, 若是你不习惯vim, 那就用sublime打开吧subl /usr/local/etc/nginx/nginx.conf

worker_processes 1; error_log /usr/local/var/log/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/log/nginx/access.log main; sendfile on; keepalive_timeout 65; port_in_redirect off; include /usr/local/etc/nginx/servers/*; }

接下来,将下面的信息放入到php-fpm文件中,vim /usr/local/etc/nginx/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; }

ok, 下面就能配置站点了,先到/usr/local/var/www目录下创建站点根目录,就叫作default吧,而后在里面创建个info.php,内容就放phpinfo()函数就行.

mkdir /usr/local/var/www/default vi /usr/local/var/www/default/info.php #输入 <?php phpinfo();

最后,去建立站点.conf文件

/usr/local/etc/nginx/servers/default.conf

输入下面的内容

server { listen 80; server_name localhost; root /usr/local/var/www/default; access_log /usr/local/var/log/nginx/default.access.log main; location / { index index.html index.htm index.php; autoindex on; include /usr/local/etc/nginx/php-fpm; } error_page 404 /404.html; error_page 403 /403.html; }

测试下配置文件

servers sudo nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
而后开启php-fpm,已经开启的就不用开了
php-fpm -D

开启nginx服务

 
sudo nginx # 已经开启的用sudo nginx -s reload 重启下/*引用自 segmentfault-周继平*/
相关文章
相关标签/搜索