1. 程式人生 > >macos下安裝NMP

macos下安裝NMP

1.安裝home-brew

2.安裝nginx

用 brew 一鍵安裝 nignx:

1 brew install nginx

如果需要安裝其他 nginx 的版本,可以 "brew edit nginx" 開啟修改 nginx 的安裝資訊包 formula,預設會用 vi 開啟,在檔案開頭處修改 nginx 相應版本的下載地址就行。

brew 執行完後,nginx 就安裝好了。和linux和windows下不同的是,nginx的二進位制檔案被安裝到了/usr/local/Cellar/nginx/bin下,而配置檔案被安裝到了/usr/local/etc/nginx下

3.安裝MySQL
1 brew installmysql

==> Summary

��  /usr/local/Cellar/openssl/1.0.2j: 1,695 files, 12M

==> Installing mysql

==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.16.el_capitan.bot

######################################################################## 100.0%

==> Pouring mysql-5.7.16.el_capitan.bottle.1.tar.gz

==> /usr/local/Cellar/mysql/5.7.16/bin/mysqld --initialize-insecure --user=dengf

==> Caveats

We've installed your MySQL database without a root password. To secure it run:

    mysql_secure_installation

To connect run:

    mysql -uroot

To have launchd start mysql now and restart at login:

  brew services start mysql

Or, if you don't want/need a background service you can just run:

  mysql.server start

==> Summary

��  /usr/local/Cellar/mysql/5.7.16: 13,511 files, 439M

執行完後,就可以在終端裡執行 "mysql",直接進入mysql資料庫裡。對,不用輸入密碼,可以直接連線,初始預設是可以匿名訪問的。超級使用者 "root" 也是沒設密碼,要設密碼的話可以執行下面指令

1 /usr/local/opt/mysql/bin/mysqladmin-u root password 'new-password'

現在訪問 mysql 還是不用密碼就可以連線,如果要設定一些登陸密碼的安全訪問限制,則需執行下面的 mysql安全安裝指令

1 /usr/local/opt/mysql/bin/mysql_secure_installation

主要是設定修改root密碼(設定過了可以不用設定,略過)、刪除匿名訪問、刪除root網路訪問、刪除test資料庫。指令執行完後,登陸mysql就需要密碼驗證了

1 mysql -u root -p
啟動MySQL服務

sudo /usr/local/MYSQL/support-files/mysql.server start

停止MySQL服務 sudo /usr/local/mysql/support-files/mysql.server stop 重啟MySQL服務 sudo /usr/local/mysql/support-files/mysql.server restart

4.安裝php56

sudo brew install php56 --with-imap --with-tidy --with-debug --with-pgsql --with-mysql --with-fpm

直接安裝可能會出現如下報錯:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require' from /usr/local/Library/Homebrew/utils.rb:308:in open' from /usr/local/Library/Homebrew/utils.rb:350:inissues_matching' from /usr/local/Library/Homebrew/utils.rb:378:in issues_for_formula' from /usr/local/Library/Homebrew/exceptions.rb:171:infetch_issues' from /usr/local/Library/Homebrew/exceptions.rb:167:in issues' from /usr/local/Library/Homebrew/exceptions.rb:207:indump' from /usr/local/Library/brew.rb:158:in rescue in <main>' from /usr/local/Library/brew.rb:66:in'

解決辦法:

  • Upgrade to the latest version of XCode
  • Make sure you reinstall XCode CLT: xcode-select --install
  • Update your formulae: brew update
  • Remove zlib: brew rm zlib
  • Install / reinstall php55: brew install php55 (as zlib is a dependency, it will be reinstalled
  • 再次執行brew命令,這次就可以安裝成功了