之前一直使用宝塔进行PHP
管理,但是macOS
系统下暂时不支持宝塔,所以就直接使用系统本地的PHP
了。
这里使用homebrew
进行安装(感谢@大卫
,让我发现原来brew
还可以安装PHP扩展
)。
这里以PHP7.4
和PHP7.1
的互相切换举例,首先安装homebrew
,这个大家应该都装了,没装的可以参考这个:
安装homebrew
之后,开始安装PHP
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
brew install php@7.4 brew install php@7.1 brew install brew-php-switcher brew services start php@7.4 echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> /Users/mcj/.bash_profile echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> /Users/mcj/.bash_profile source ~/.bash_profile pecl install pcntl |
PHP安装成功之后会提示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/usr/local/Cellar/php@7.2/7.2.34_4/bin/pear config-set php_ini /usr/local/etc/php/7.2/php.ini system dyld: Library not loaded: /usr/local/opt/tidy-html5/lib/libtidy.5.dylib Referenced from: /usr/local/Cellar/php@7.2/7.2.34_4/bin/php Reason: image not found Warning: The post-install step did not complete successfully You can try again using: brew postinstall php@7.2 ==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module /usr/local/opt/php@7.2/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.2/ php@7.2 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.2 first in your PATH, run: echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> /Users/mcj/.bash_profile echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> /Users/mcj/.bash_profile For compilers to find php@7.2 you may need to set: export LDFLAGS="-L/usr/local/opt/php@7.2/lib" export CPPFLAGS="-I/usr/local/opt/php@7.2/include" To start php@7.2: brew services start php@7.2 Or, if you don't want/need a background service you can just run: /usr/local/opt/php@7.2/sbin/php-fpm --nodaemonize ==> Summary ? /usr/local/Cellar/php@7.2/7.2.34_4: 515 files, 75MB |
如果想要切换7.2
,只需要执行:
brew-php-switcher 7.2
然后按照要求写入.bash_profile
即可。
本文最后更新于2021年9月6日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!