一、mac安裝Homebrew,更新 nginx php7 mysql 環境
//檢視版本 brew -v //安裝homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
國內Homebrew映象 ,更換映象源加速:
cd "$(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/brew.git brew update brew -v
安裝 啟動 nginx
brew cleanup//移除舊版本 brew install nginx //啟動nginx,如果更新安裝nginx,啟動時常會提示沒有許可權,則刪除之前的logs資料夾中的檔案等 sudo nginx//啟動 //檢視狀態 ps -ef|grep nginx nginx -V sudo nginx -s reload//重新載入配置 sudo nginx -s stop//關閉 lsof -i tcp:80//檢視80端口占用情況 ps aux | grep nginx//檢視nginx程序
配置nginx 虛擬主機,通過域名訪問本地web專案
server { listen 80; server_namewww.dtemp.com; root /Users/free/www/learnlaravel/; access_log /usr/local/var/logs/nginx/dtemp.access.log; location / { if (!-e $request_filename){ rewrite ^/(.*) /index.php last; } index index.html index.htm index.php; autoindex on; include /usr/local/etc/nginx/conf.d/php-fpm; } } // include /usr/local/etc/nginx/conf.d/php-fpm; //這個檔案內容: location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_intercept_errors on; include /usr/local/etc/nginx/fastcgi.conf; } //以上內容表示如果nginx接到的請求是.php結尾的php程式, //則將請求轉發到本機9000埠,而這個埠是php-fpm在監聽, //當未安裝php時,請求www.dtemp.com會返回502錯誤
搜尋安裝php
brew search php brew install [email protected] php -v //檢視版本 php -m //檢視擴充套件
//安裝完php7會輸出以下內容,實際是一個簡單guid, //執行 brew services start [email protected]啟動php-fpm The php.ini and php-fpm.ini file can be found in: /usr/local/etc/php/7.2/ [email protected] is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula. If you need to have [email protected] first in your PATH run: //*執行下面兩行命令,就會將php7命令路徑加入環境變數 echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile echo 'export PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.bash_profile For compilers to find [email protected] you may need to set: export LDFLAGS="-L/usr/local/opt/[email protected]/lib" export CPPFLAGS="-I/usr/local/opt/[email protected]/include" To have launchd start [email protected] now and restart at login: brew services start [email protected] Or, if you don't want/need a background service you can just run: php-fpm
laravel環境要求如下,新建test.php在web目錄,可以清楚看到php配置和擴充套件等資訊
PHP >= 7.1.3 OpenSSL PHP Extension PDO PHP Extension Mbstring PHP Extension Tokenizer PHP Extension XML PHP Extension Ctype PHP Extension JSON PHP Extension BCMath PHP Extension test.php 內容: <?php phpinfo();?>
安裝mysql,通過官網下載社群版
https://dev.mysql.com/downloads/mysql/brew 覆蓋安裝老版本往往有些坑,使用dmg安裝一路next簡易操作,只有一點需要注意。 老版連線mysql的客戶端使用的舊版加密,mysql8安裝時會預設選擇加強加密,可以選擇老版加密,避免更好客戶端。
navicat 檢視mysql資料庫很方便,推薦一個下載地址:https://xclient.info/search/s/navicat/