mac下homebrew安裝及php.mysql.nginx環境安裝及配置


homebrew 的安裝

終端中輸入

ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

安裝php-fpm

因為已經安裝homebrew 所以可以直接使用homebrew安裝php-fpm

brew tap homebrew/dupes
brew tap homebrew/php
brew install --without-apache --with-fpm --with-mysql php56

安裝完成 現在我們將php-fpm 添加入環境變量中 方便我們通過終端直接進行啟動

使用bash的話輸入下面這個命令
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile
使用zsh的話輸入下面這個命令
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc

創建文件夾 並啟動服務

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

如果沒有報出什么bug的話 在終端中鍵入

lsof -Pni4 | grep LISTEN | grep php

應該會有下圖的顯示

php-fpm   69659  frdmn    6u  IPv4 0x8d8ebe505a1ae01      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   69660  frdmn    0u  IPv4 0x8d8ebe505a1ae01      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   69661  frdmn    0u  IPv4 0x8d8ebe505a1ae01      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   69662  frdmn    0u  IPv4 0x8d8ebe505a1ae01      0t0  TCP 127.0.0.1:9000 (LISTEN)

mysql 安裝

brew install mysql
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

添加mysql到環境變量中

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

進入mysql的初始化環節 去確認一些mysql的缺省選項

mysql_secure_installation
>Enter current password for root (enter for none)
回車 我們並不需要


> Change the root password? [Y/n]
如不願意使用root密碼缺省mysql的password 輸入n
並鍵入自己想使用的password

> Remove anonymous users? [Y/n]
Yes. 匿名用戶我們並不需要

> Disallow root login remotely? [Y/n]
Yes. 我們僅需要127.0.1 

> Remove test database and access to it? [Y/n]
Yes. 無需保留冗余的測試文件

> Reload privilege tables now? [Y/n]
Yes.重新加載數據庫

測試mysql

mysql -uroot -p

輸入權限密碼
這是你應該能看見

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
退出mysql 輸入q

php-fpm安裝及配置

curl -L https://gist.github.com/frdmn/7853158/raw/php-fpm -o /usr/local/etc/nginx/conf.d/php-fpm

注意牆內用戶最好翻牆 不然timeout是你的噩夢

創建默認虛擬主機

curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default -o /usr/local/etc/nginx/sites-available/default
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_default-ssl -o /usr/local/etc/nginx/sites-available/default-ssl
curl -L https://gist.github.com/frdmn/7853158/raw/sites-available_phpmyadmin -o /usr/local/etc/nginx/sites-available/phpmyadmin

使用git 來克隆實例主機

git clone http://git.frd.mn/frdmn/nginx-virtual-host.git /var/www
rm -rf /var/www/.git

然后刪除/var/www/.get文件夾 防止你的文件被git上傳

nginx的安裝

使用homebrew來安裝nginx

brew install nginx

我們必須確保80端口是開啟的,因為nginx是基於80端口的

sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons/
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

第一次開始nginx

sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

默認的配置設置是將監聽8080端口而非http默認的80端口

curl -IL http://127.0.0.1:8080

終端中應該有如下顯示

HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Mon, 19 Oct 2014 19:07:47 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Mon, 19 Oct 2014 19:01:32 GMT
Connection: keep-alive
ETag: "5444dea7-264"
Accept-Ranges: bytes

我們停止nginx 對其進行進一步配置

sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

安裝ssl

創建文件夾來存放ssl的證書和私鑰

mkdir -p /usr/local/etc/nginx/ssl

生成4096比特 的RSA秘鑰

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

sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

然后你可以 打開下面的這些網站,來確認自己的nginx是否正確安裝

http://localhost → "Nginx works" page
http://localhost/info → phpinfo()
http://localhost/nope → " Not Found" page
https://localhost:443 → "Nginx works" page (SSL)
https://localhost:443/info → phpinfo() (SSL)
https://localhost:443/nope → "Not Found" page (SSL)
https://localhost:306 → phpMyAdmin (SSL)

對服務的控制

因為種種原因 我們可能要重新啟動來進行 重命名

curl -L https://gist.github.com/frdmn/7853158/raw/bash_aliases -o /tmp/.bash_aliases
cat /tmp/.bash_aliases >> ~/.bash_aliases
// 如果你使用bash的話,輸入下面這個命令
echo "source ~/.bash_aliases" >> ~/.bash_profile
// 如果你使用zsh的話,輸入下面這個命令
echo "source ~/.bash_aliases" >> ~/.zshrc

現在我們可以輸入以下命令更新我們的變量 讓我們的設置生效

//如果你使用bash的話,輸入下面這個命令
source ~/.bash_profile
 //如果你使用zsh的話,輸入下面這個命令
source ~/.zshrc

現在你可以使用更加簡短的命名來優雅的開關服務 而不必打一長串的指令 路徑 那很傻

nginx.start
nginx.stop
nginx.restart

要快速地瀏覽的最新錯誤或訪問日志

nginx.logs.access
nginx.logs.default.access
nginx.logs.phpmyadmin.access
nginx.logs.default-ssl.access
nginx.logs.error
nginx.logs.phpmyadmin.error

或者檢查配置文件

sudo nginx -t


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM