简体   繁体   English

使用 brew 将 PHP 更新到 7.4 macOS Catalina

[英]Update PHP to 7.4 macOS Catalina with brew

I try to update my PHP version to 7.4 on macOS Catalina with brew.我尝试使用 brew 在 macOS Catalina 上将我的 PHP 版本更新到7.4

I did brew install php@7.4我做了brew install php@7.4

If I check my version php -v , I still see the old version PHP 7.3.11 ?如果我检查我的版本php -v ,我仍然看到旧版本PHP 7.3.11吗?

What do I have to do?我需要做什么?

Update:更新:

After brew doctor I get:brew doctor我得到:

Warning: Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin.警告:在您的 PATH 中未找到 Homebrew 的 sbin,但您已经安装了将可执行文件放入 /usr/local/sbin 的公式。 Consider setting the PATH for example like so: echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.profile考虑像这样设置 PATH:echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.profile

您可以在php@7.2 中找到我的类似答案。

  • brew install php@7.4
  • brew link --force --overwrite php@7.4
  • brew services start php@7.4
  • export PATH="/usr/local/opt/php@7.4/bin:$PATH"
  • export PATH="/usr/local/opt/php@7.4/sbin:$PATH"

try:尝试:

brew update
brew upgrade php
php -v
brew services start php

or或者

brew services restart php

if you use apache server:如果您使用 apache 服务器:

sudo apachectl restart

if you use ngnix如果你使用 ngnix

sudo nginx -s reload

Edit:编辑:

brew unlink php@7.3
brew link php@7.4

If anyone want to downgrade php from latest 8.1.2 to 7.4 on systems demand, try the below commands with homebrew: Installing PHP 7.4:如果有人想根据系统需求将 php 从最新的 8.1.2 降级到 7.4,请使用自制软件尝试以下命令:安装 PHP 7.4:

brew install php@7.4
brew services restart php
brew unlink php@8.1
brew link php@7.4
echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

Or要么

export PATH="/usr/local/opt/php@7.4/bin:$PATH"
export PATH="/usr/local/opt/php@7.4/sbin:$PATH" 

I recently faced this issue, all the suggestion here didn't work until I ran:我最近遇到了这个问题,直到我跑了,这里的所有建议才奏效:

xcode-select --install

Then ran the command I was trying before and the error stopped, for my case it was php然后运行我之前尝试过的命令,错误停止了,就我而言,它是 php

dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib Referenced from: /usr/local/opt/php@7.4/bin/php Reason: image not found zsh: abort php -v dyld:库未加载:/usr/local/opt/openldap/lib/libldap-2.4.2.dylib 引用自:/usr/local/opt/php@7.4/bin/php 原因:找不到图像 zsh:中止 php -v

Using terminal of MacOS.使用 MacOS 终端。 Don't use terminal in vscode.不要在 vscode 中使用终端。

  1. I move to directory by: cd /usr/local我移动到目录: cd /usr/local
  2. Find the file location by: find /usr/local/ -name libphp7.so.通过以下方式查找文件位置:find /usr/local/ -name libphp7.so。 (Then get the file location at: /usr/local//Cellar/php@7.4/7.4.23/lib/httpd/modules/libphp7.so. I copy this.) (然后在以下位置获取文件位置:/usr/local//Cellar/php@7.4/7.4.23/lib/httpd/modules/libphp7.so。我复制这个。)
  3. I open the file by: sudo vim /etc/apache2/httpd.conf我通过以下方式打开文件: sudo vim /etc/apache2/httpd.conf
  4. Look for the line by: /libphp7.so通过以下方式查找该行:/libphp7.so
  5. Uncomment the line and update the line by: LoadModule php7_module /usr/local//Cellar/php@7.4/7.4.23/lib/httpd/modules/libphp7.so取消注释该行并通过以下方式更新该行: LoadModule php7_module /usr/local//Cellar/php@7.4/7.4.23/lib/httpd/modules/libphp7.so
  6. Restart apache by: sudo apachectl restart通过以下方式重新启动 apache: sudo apachectl restart
  7. Verify PHP by accessing http://localhost/phpinfo.php通过访问 http://localhost/phpinfo.php 验证 PHP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM