安裝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安裝下吧蛋叼,安裝時(shí)的消息有這么一句話We've installed your MySQL database without a root password. To secure it run:mysql_secure_installation,那就來(lái)設(shè)置下root的密碼
# 第一步:打開mysql服務(wù)
mysql.server start
# 第二步:執(zhí)行mysql_secure_installation
mysql_secure_installation # 執(zhí)行后按照提示信息進(jìn)行設(shè)置,慢慢看下英文崇渗,都能看懂的
好了瞻赶,進(jìn)入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擴(kuò)展
brew update # 安裝軟件前都要習(xí)慣的更新下brew源
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
現(xiàn)在brew search php就可以了叹螟,出來(lái)一堆版本的php鹃骂,我們就安裝php7.0版本吧,我用php7.1版本在跑laravel的時(shí)候首妖,出現(xiàn)過(guò)錯(cuò)誤偎漫,我那時(shí)候沒有解決掉爷恳,裝回php7.0沒有問(wèn)題有缆。
可以先brew options php70看看你安裝的時(shí)候要哪些選項(xiàng),我選擇了下面這些,因?yàn)楹竺嫖覀儠?huì)用nginx作為反向代理温亲,所以就不要用--with-apache選項(xiàng)了棚壁,也不要添加--without-fpm選項(xiàng)
brew install php70 --with-debug --with-gmp --with-homebrew-curl --with-homebrew-libressl --with-homebrew-libxml2 --with-homebrew-libxslt --with-imap --with-libmysql --with-mysql
由于Mac自帶了php和php-fpm,因此需要添加系統(tǒng)環(huán)境變量PATH來(lái)替代自帶PHP版本,我們用的是zsh,所以放進(jìn).zshrc中,如果你用的shell是bash,那么可以把下面的信息寫入到~/.bash_profile文件中栈虚,如果這個(gè)文件沒有袖外,你自己建一個(gè)就行。
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
測(cè)試下效果
# 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, 我以前的項(xiàng)目有些依賴不支持php7,所以這個(gè)我是留著的魂务,隨時(shí)切換使用
? ~ /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
? ~
下面先來(lái)看下php-fpm的配置文件曼验,路徑在/usr/local/etc/php/7.0/php-fpm.conf, 大家應(yīng)該都猜的到泌射。我們主要看下pid和log文件會(huì)放在哪里
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行前面的分號(hào),使用php-fpm -t測(cè)試下配置是否正確,按提示信息是不管它也可以鬓照,默認(rèn)就是在/usr/local/var路徑下的熔酷,不過(guò)還是設(shè)置下吧;
? 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的一些管理:
#測(cè)試php-fpm配置
php-fpm -t
#啟動(dòng)php-fpm
php-fpm -D
#關(guān)閉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命令來(lái)管理php-fpm
brew services start|stop|restart php70
#還可以用這個(gè)命令來(lái)管理php-fpm
php70-fpm start|stop|restart
啟動(dòng)php-fpm之后豺裆,確保它正常運(yùn)行監(jiān)聽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)
全新安裝Mac OS Sierra (10.12)并使用HomeBrew安裝ZSH + MNMP (Mac + Nginx + Mysql + Php) 開發(fā)環(huán)境(三)