MAC重裝環(huán)境
重裝brew
1、刪除brew
<pre>
rm -rf /usr/local/Cellar /usr/local/opt /usr/local/.git
rm -rf ~/Library/Caches/Homebrew
brew prune
brew cleanup
</pre>
2、重裝brew
3、更改權限
sudo chown -R whoami
/usr/local
4、測試
<pre>
brew doctor
brew prune
brew cleanup
brew update
</pre>
安裝zsh
curl -L http://install.ohmyz.sh | sh
安裝 Nginx + php + mysql
1、安裝Nginx
<pre>
brew search nginx
brew install nginx
brew info nginx
參考:http://www.mamicode.com/info-detail-1445840.html
開機自啟動:
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
無權限的:
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
加權限:
sudo chown root:wheel /usr/local/Cellar/nginx/1.2.6/bin/nginx
sudo chmod u+s /usr/local/Cellar/nginx/1.2.6/bin/nginx
</pre>
2、安裝mysql
<pre>
brew search mysql
brew install homebrew/versions/mysql56
開機自啟動:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql56.plist
配置文件配置方法:
brew install mysql (安裝)
添加修改mysql配置
mysqld --help --verbose | more (查看幫助, 按空格下翻)
你會看到開始的這一行(表示配置文件默認讀取順序)
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
通常這些位置是沒有配置文件的, 所以要自己建一個
ls $(brew --prefix mysql)/support-files/my-* (用這個可以找到樣例.cnf)
cp /usr/local/opt/mysql/support-files/my-default.cnf /etc/my.cnf (拷貝到第一個默認讀取目錄)
按需修改my.cnf
brew services start mysql (啟動)
brew services stop mysql (停止)
</pre>
2、安裝php
<pre>
brew update
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php56 --with-fpm --without-apache --with-imap
brew install php56-memcache php56-xdebug php56-swoole php56-memcached php56-mongo php56-redis php56-gearman
</pre>
xhprof PHP的性能監(jiān)控神器
brew install php56-xhprof
https://pecl.php.net/package/xhprof
由于OSX已經自帶了PHP環(huán)境,因此需要修改系統(tǒng)路徑,優(yōu)先運行brew安裝的版本,在~/.bashrc里加入:
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
記住添加軟連接
sudo ln -s /usr/local/Cellar/php56/5.6.31_7/sbin/php-fpm /usr/local/bin/php-fpm
安裝工具
brew install node git
進程相關
<pre>
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
以下是launchd的相關配置的存放目錄:
~/Library/LaunchAgents 用戶的進程
/Library/LaunchAgents 管理員設置的用戶進程
/Library/LaunchDaemons 管理員提供的系統(tǒng)守護進程
/System/Library/LaunchAgents Mac操作系統(tǒng)提供的用戶進程
/System/Library/LaunchDaemons Mac操作系統(tǒng)提供的系統(tǒng)守護進程
可以看到,一般我們個人編寫的守護進程,都應該放到~/Library/LaunchAgents目錄里面。
</pre>
環(huán)境變量相關
<pre>
mac 一般使用bash作為默認shell
Mac系統(tǒng)的環(huán)境變量,加載順序為:
/etc/profile /etc/paths ~/.bash_profile ~/.bash_login ~/.profile ~/.bashrc
【說明:】
/etc/profile和/etc/paths是系統(tǒng)級別的,系統(tǒng)啟動就會加載.
后面幾個是當前用戶級的環(huán)境變量,這3個按照從前往后的順序讀取,如果~/.bash_profile文件存在,則后面的幾個文件就會被忽略不讀了,
如果~/.bash_profile文件不存在,才會以此類推讀取后面的文件。
~/.bashrc沒有上述規(guī)則,它是bash shell打開的時候載入的。
</pre>
設置PATH的語法都為:#中間用冒號隔開:
export PATH=$PATH:<PATH 1>:<PATH 2>:<PATH 3>:------:<PATH N>
(一)全局設置
下面的幾個文件設置是全局的,修改時需要root權限
1)/etc/paths (全局建議修改這個文件 )
編輯 paths,將環(huán)境變量添加到 paths文件中 ,一行一個路徑
Hint:輸入環(huán)境變量時,不用一個一個地輸入,只要拖動文件夾到 Terminal 里就可以了。
2)/etc/profile (建議不修改這個文件 )
全局(公有)配置,不管是哪個用戶,登錄時都會讀取該文件。
3)/etc/bashrc (一般在這個文件中添加系統(tǒng)級環(huán)境變量)
全局(公有)配置,bash shell執(zhí)行時,不管是何種方式,都會讀取此文件。
4)
1.創(chuàng)建一個文件:
sudo touch /etc/paths.d/mysql
2.用 vim 打開這個文件(如果是以 open -t 的方式打開,則不允許編輯):
sudo vim /etc/paths.d/mysql
3.編輯該文件,鍵入路徑并保存(關閉該 Terminal 窗口并重新打開一個,就能使用 mysql 命令了)
/usr/local/mysql/bin
據說,這樣可以自己生成新的文件,不用把變量全都放到 paths 一個文件里,方便管理。
(二)單個用戶設置
1)~/.bash_profile (任意一個文件中添加用戶級環(huán)境變量)
(注:Linux 里面是 .bashrc 而 Mac 是 .bash_profile)
若bash shell是以login方式執(zhí)行時,才會讀取此文件。該文件僅僅執(zhí)行一次!默認情況下,他設置一些環(huán)境變量
設置命令別名alias ll=’ls -la’
設置環(huán)境變量:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
2)~/.bashrc 同上
如果想立刻生效,則可執(zhí)行下面的語句:
$ source 相應的文件
一般環(huán)境變量更改后,重啟后生效。