本文翻译自:https://stitcher.io/blog/php-8-upgrade-mac
用homebrew升级
首先要确保brew是最新的:
brew update
接下来,升级php:
brew upgrade php
通过运行php -v以下命令检查当前版本:
php -v
重新启动nginx或apache:
sudo nginx -s reloadsudo apachectl restart
并通过访问以下脚本确保本地web服务器也使用php 8:
# index.php, accessible to your web serverphpinfo();
版本应显示8.0.x。
注意:如果您使用的是laravel valet,请继续阅读,您需要一些额外的步骤才能使web服务器正常工作。
valet
如果您使用的是laravel valet,则应执行以下步骤对其进行升级:
composer global update
现在运行valet install:
valet install
扩展
php扩展是使用pecl安装的。我个人使用imagick,redis和xdebug。它们可以这样安装:
pecl install imagickpecl install redispecl install xdebug
您可以运行pecl list以查看安装了哪些扩展:
pecl list# installed packages, channel pecl.php.net:# =========================================# package version state# imagick 3.4.4 stable# redis 5.1.1 stable# xdebug 2.8.0 stable
您可以使用来搜索其他扩展名pecl search:
pecl search pdf# retrieving data...0%# ..# matched packages, channel pecl.php.net:# =======================================# package stable/(latest) local# pdflib 4.1.2 (stable) creating pdf on the fly with the pdflib library
安装新软件包后,请确保重新启动web服务器:
sudo nginx -s reloadsudo apachectl restart
如果您使用的是laravel valet,则也应重新启动它。
valet restart
通过检查php web服务器和cli安装,确保正确安装和加载了所有扩展:
php -i | grep redisvar_dump(extension_loaded('redis'));
如果扩展未正确加载,则有两个简单的修复程序。
首先,请确保将扩展名添加到正确的ini文件中。您可以运行php --ini以了解哪个文件已加载:
configuration file (php.ini) path: /usr/local/etc/php/7.4loaded configuration file: /usr/local/etc/php/7.4/php.iniscan for additional .ini files in: /usr/local/etc/php/7.4/conf.dadditional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
现在检查ini文件:
extension="redis.so"extension="imagick.so"zend_extension="xdebug.so"
请注意,如果您正在通过cli测试已安装的扩展程序,则在更改ini设置时无需重新启动nginx,apache或valet。
如果要从也使用pecl安装扩展程序的旧php版本进行更新,则可以做第二件事。是分别重新安装每个扩展。
pecl uninstall imagickpecl install imagick
最后一步
最后,您应该测试和升级项目以实现php 8兼容性。
更多php8相关特性,请访问php8专题栏目!
以上就是在mac上使用homebrew升级到php 8的详细内容。
