最近更換電腦了,換成蘋果mac,嘗試自己配置php的可開發環境,發現問題簡直是一大堆,太多關於環境部署的知識點了的,真是學無止境......,現將我的一頓胡亂操作記錄如下:
因爲蘋果電腦自帶ruby,可以使用ruby安裝brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝的過程當中可能匯遇到下面的問題:
mac 安裝homebrew出錯 Failed to connect to raw.githubusercontent.com port 443: Connection refused error:
解決辦法如下,重裝command line tools,再執行安裝指令,homebrew安裝成功。
removing the old tools ($ rm -rf /Library/Developer/CommandLineTools)
install xcode command line tools again ($ xcode-select --install).
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
以上參考https://blog.csdn.net/heroacool/article/details/102844367
安裝brew成功後,如果覺得下載源很慢的情況下,可以採取以下的方法:
Mac下brew更換國內鏡像源最新方法
brew 是一個很好地Mac下管理應用包的工具,可是第一次安裝後直接使用時,下載和更新很慢,這是因爲brew的鏡像源在國外,我們的網絡訪問會很慢,不過我們可以修改鏡像源爲國內,網上有很多博客提供的方法,我試了很多,大部分都過時了,以下是我經過測試截止2019年最新的官方方法更換爲國內鏡像源(清華大學)
cd /usr/local/Homebrew
git -C “$(brew --repo)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C “$(brew --repo homebrew/core)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C “$(brew --repo homebrew/cask)” remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update
在使用過最後brew update後,需要等待一部分時間,大概一分鐘,如果看見終端上方一直在變化就離成功不遠了,最後會在終端中顯示更新信息,就算是大功告成了。復原的方法
cd /usr/local/Homebrew
git -C “$(brew --repo)” remote set-url origin https://github.com/Homebrew/brew.git
git -C “$(brew --repo homebrew/core)” remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C “$(brew --repo homebrew/cask)” remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update
最新的設置與復原方法參考;https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/
上述經驗參考博文地址:https://blog.csdn.net/weixin_40475396/article/details/104042037
卸載brew的方法:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
brew -v 可以查看brew的版本
安裝完brew後,有以下這些常用的操作:
簡單使用:
安裝軟件:brew install 軟件名,例:brew install wget
搜索軟件:brew search 軟件名,例:brew search wget
卸載軟件:brew uninstall 軟件名,例:brew uninstall wget
更新所有軟件:brew update
更新具體軟件:brew upgrade 軟件名 ,例:brew upgrade git
顯示已安裝軟件:brew list
查看軟件信息:brew info/home 軟件名 ,例:brew info git / brew home git
PS:brew home指令是用瀏覽器打開官方網頁查看軟件信息
查看哪些已安裝的程序需要更新: brew outdated
顯示包依賴:brew reps
顯示幫助:brew help
以上操作參考博客地址:https://blog.csdn.net/qq_41234116/article/details/79366454
有人說在mac上設置:export ALL_PROXY=socks5://127.0.0.1:portnumber
這樣可以加快終端下載速度,我這邊嘗試效果不明顯,
tips:portnumber取決於自己電腦的端口(1086),以上參考博文地址:
https://www.jianshu.com/p/a9d9f00daf30
brew install [email protected]
brew install [email protected]
vim ~/.bash_profile可以配置php環境變量
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/sbin:$PATH"
安裝配置Apache
brew install httpd
配置(去掉註釋或添加註釋)
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
LoadModule php7_module /usr/local/Cellar/[email protected]/7.2.18/lib/httpd/modules/libphp7.so
AddHandler application/x-httpd-php .php
ServerName localhost:80
Listen 80
#僞靜態配置
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
在extra/httpd-vhosts.conf配置虛擬主機
<VirtualHost *:80>
ServerName xxx
DocumentRoot xxx
<Directory "xxx">
DirectoryIndex index.html index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "/usr/local/var/log/httpd/error_log"
CustomLog "/usr/local/var/log/httpd/access_log" common
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1$1 [L,R=permanent]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-f
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-d
RewriteRule "^" "/index.php" [L]
</VirtualHost>
重啓Apache
sudo apachectl restart
配置apache 開機啓動命令操作如下:
brew services start httpd
以上安裝經驗總結參考博文地址:
https://www.jianshu.com/p/bc087c8235b7,根據該參考整理的。