看網上不少資料,大多數都是php
mac安裝php,只須要:html
brew tap homebrew/php brew install phpXX
安裝php擴展只須要:nginx
brew install phpXX-phpExtension
可是執行上面兩條命令的時候都會拋出error:git
homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.
homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.
即Homebrew/php已經棄用了,其餘第三方tap也已經棄用或者遷移了,參考:
github
https://github.com/Homebrew/homebrew-phpredis
如今執行一下瀏覽器
brew search php
出現的是:php7
再也不是以往的一大片各類版本的php以及擴展任君選擇了,而擴展方面,以往咱們是這樣安裝擴展的:php-fpm
brew install php71-redis
如今已經搜不出來:測試
那麼如今怎麼安裝php及擴展呢,上述github連接已經說的很明白,有興趣的能夠本身去看,我這裏簡單說一下。
下面舉例安裝php7.1
首先
brew tap Homebrew/homebrew-core
由於其餘第三方tab已經遷移/棄用了,所有合併到這裏
如今仍然能夠經過
brew install php71
來安裝php7.1,可是其實你會看到php71已經改名爲php@7.1:
安裝過程截圖:
安裝成功截圖:
啓動 php-fpm
brew services start php@7.1
設置開機啓動:
cp /usr/local/Cellar/php\@7.1/7.1.29/homebrew.mxcl.php\@7.1.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew-php.josegonzalez.php\@7.1.plist
設置 Nginx 的 PHP-FPM 配置
打開 nginx 默認註釋掉的php location設置,修改以下(具體配置參數,例如路徑,這裏以我本地安裝爲準):
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/var/www$fastcgi_script_name; include /usr/local/etc/nginx/fastcgi_params; }
測試nginx配置是否正確:
StevendeMacBook-Pro:nginx steven$ nginx -t nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied) nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok 2019/05/21 16:35:46 [emerg] 96011#0: open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
由於我同時打開了日誌,根據提示,說明日誌文件夾沒有權限
sudo chmod -R 777 /usr/local/var/log/nginx/
給他權限
再試試:
StevendeMacBook-Pro:log steven$ sudo nginx -t nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: [emerg] open() "/usr/local/Cellar/nginx/1.15.12/logs/access.log" failed (2: No such file or directory) nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
哦,這裏沒有/usr/local/Cellar/nginx/1.15.12/logs logs文件夾,去建立一個就OK,並賦予權限
mkdir /usr/local/Cellar/nginx/1.15.12/logs chmod -R 777 logs/
再試試:
StevendeMacBook-Pro:1.15.12 steven$ sudo nginx -t nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
成功了,重載nginx配置
sudo nginx -s reload
由於個人nginx解析的根目錄是
/usr/local/var/www
因此,去這個目錄下建立一個phpinfo.php文件,寫入代碼
<?php echo phpinfo(); ?>
瀏覽器訪問 http://localhost:8080/phpinfo.php
說一下要用到的幾個位置
php-fpm在/usr/local/Cellar/php@7.1/7.1.22/sbin/php-fpm
php和fpm的相關配置在/usr/local/etc/php/7.1
安裝php擴展:
直接pecl install phpExtension(如:pecl install redis)
擴展放置的位置開發者已經設置好,在/usr/local/lib/php/pecl/20160303