del*_*les 5 php macos homebrew macos-big-sur
我已经使用自制软件安装了 PHP 7.4 的更新版本。
但是,当我在命令行上运行 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: Dec 21 2020 21:33:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
Run Code Online (Sandbox Code Playgroud)
如您所见,它仍在使用 Mac Os 附带的那个。
当我从 php 脚本运行 phpinfo 时,我可以看到它使用了正确的脚本,就像我在 Apache 上配置的那样,如下所示。
我需要做什么才能使命令行使用 brew 安装的 PHP 版本?
安装软件包后,Homebrew会向您显示一些有用的信息,您必须注意这些信息。
无论如何,您可以通过运行以下命令来访问该信息。
brew info php@7.4
Run Code Online (Sandbox Code Playgroud)
如果您注意到有一个如下所示的“注意事项”部分,它包含一些您必须手动执行的配置。
==> 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 restart php@7.4 after an upgrade:
brew services restart php@7.4
Or, if you don't want/need a background service you can just run:
/usr/local/opt/php@7.4/sbin/php-fpm --nodaemonize
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您必须通过在终端中运行这些命令来将以下行添加到 shell runcom 文件中,如果您使用Zsh,则应该是 ,~/.zshrc如果您使用的是Bash,则应该是~/.bashrc.
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> path/to/runcom/file
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> path/to/runcom/file
Run Code Online (Sandbox Code Playgroud)
这会将 Hombrew 安装的 PHP 添加到路径中,并且比 macOS 捆绑的 PHP 更喜欢它。
| 归档时间: |
|
| 查看次数: |
2154 次 |
| 最近记录: |