mac终端执行
php -v
得到的输出是
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Nov 23 2020 06:45:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
意思是说本身就带了php7.3,未来的版本可能会去掉,我已经安装了homebrew,此时我执行命令
brew services list
输出Name Status User Plist
activemq stopped
elasticsearch stopped
kafka stopped
kibana stopped
mongodb-community started java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mysql@5.7 started java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx error java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.nginx.plist
redis started java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.redis.plist
zookeeper stopped
继续
brew search php
输出
==> Formulae
brew-php-switcher ✔ exolnet/deprecated/php@7.1 php-cs-fixer php@7.4 phpmyadmin
exolnet/deprecated/php@5.6 php php@7.2 phplint phpstan
exolnet/deprecated/php@7.0 php-code-sniffer php@7.3 phpmd phpunit ✔
==> Casks
eclipse-php
继续
brew install php@7.4
输出
Updating Homebrew...
^Cgit -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
==> Downloading https://homebrew.bintray.com/bottles/php%407.4-7.4.13_1.big_sur.bottle.tar.gz
^C
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
fatal: cannot change to '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts': No such file or directory
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
fatal: cannot change to '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts': No such file or directory
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
fatal: cannot change to '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts': No such file or directory
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
java0904@weigongdeMacBook-Pro ~ % git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
fatal: cannot change to '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-fonts': No such file or directory
java0904@weigongdeMacBook-Pro ~ % brew install php@7.4
Updating Homebrew...
^C==> Downloading https://homebrew.bintray.com/bottles/php%407.4-7.4.13_1.big_sur.bottle.tar.gz
Already downloaded: /Users/java0904/Library/Caches/Homebrew/downloads/818ed98a789fd90b815576c5869d1f615d3f397eeb158931624cd6b469b5196d--php@7.4-7.4.13_1.big_sur.bottle.tar.gz
==> Pouring php@7.4-7.4.13_1.big_sur.bottle.tar.gz
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set php_ini /usr/local/etc/php/7.4/php.ini system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set php_dir /usr/local/share/pear@7.4 system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set doc_dir /usr/local/share/pear@7.4/doc system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set ext_dir /usr/local/lib/php/pecl/20190902 system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set bin_dir /usr/local/opt/php@7.4/bin system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set data_dir /usr/local/share/pear@7.4/data system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set cfg_dir /usr/local/share/pear@7.4/cfg system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set www_dir /usr/local/share/pear@7.4/htdocs system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set man_dir /usr/local/share/man system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set test_dir /usr/local/share/pear@7.4/test system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear config-set php_bin /usr/local/opt/php@7.4/bin/php system
==> /usr/local/Cellar/php@7.4/7.4.13_1/bin/pear update-channels
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.4/
php@7.4 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 php@7.4 first in your PATH run:
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
For compilers to find php@7.4 you may need to set:
export LDFLAGS="-L/usr/local/opt/php@7.4/lib"
export CPPFLAGS="-I/usr/local/opt/php@7.4/include"
To have launchd start php@7.4 now and restart at login:
brew services start php@7.4
Or, if you don't want/need a background service you can just run:
php-fpm
==> Summary
/usr/local/Cellar/php@7.4/7.4.13_1: 497 files, 72.3MB
按照提示执行一下两个命令
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc
继续执行
vim ~/.zshrc
将以下内容黏贴到.zshrc文件中
执行
source ~/.zshrc
执行
php -v
输出
PHP 7.4.13 (cli) (built: Nov 30 2020 14:57:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
java0904@**MacBook-Pro ~ % cd /usr/local/Cellar/nginx/1.19.2/bin
执行
brew services start php@7.4
输出
Service `php@7.4` already started, use `brew services restart php@7.4` to restart.
java0904@**MacBook-Pro bin % brew services restart php@7.4
Stopping `php@7.4`... (might take a while)
==> Successfully stopped `php@7.4` (label: homebrew.mxcl.php@7.4)
==> Successfully started `php@7.4` (label: homebrew.mxcl.php@7.4)
执行
brew services list
输出
Name Status User Plist
activemq stopped
elasticsearch stopped
kafka stopped
kibana stopped
mongodb-community started java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mysql@5.7 started java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx error java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.nginx.plist
php@7.4 error java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.php@7.4.plist
redis started java0904 /Users/java0904/Library/LaunchAgents/homebrew.mxcl.redis.plist
zookeeper stopped
不知道为什么php@7.4 的状态是error执行
sudo php-fpm
输出
[26-Dec-2020 21:30:41] NOTICE: fpm is running, pid 4572
[26-Dec-2020 21:30:41] NOTICE: ready to handle connections
安装php扩展
输出
sudo pecl install redis
一路yes,最后输出
checking for igbinary includes... configure: error: Cannot find igbinary.h
ERROR: `/private/tmp/pear/install/redis/configure --with-php-config=/usr/local/opt/php@7.4/bin/php-config --enable-redis-igbinary=yes --enable-redis-lzf=yes --enable-redis-zstd=yes' failed
执行
sudo pecl install igbinary
输出pecl/igbinary is already installed and is the same as the released version 3.1.6
install failed
于是我的逻辑是先删除,再安装
于是执行下面两个命令
sudo pecl uninstall igbinary
sudo pecl install igbinary
成功之后执行真正的安装sudo pecl install redis
sudo pecl install mongodb
此时执行查看扩展模块
php -m
已经可以看到上面的安装的模块都在里面了,但是访问index.php,却没有看到这两个扩展,原因是没有重启php,需要执行以下命令
sudo killall php-fpm
sudo php-fpm
发表评论 取消回复