

Upgrade to PHP 8.1 with Homebrew on Mac
source link: https://www.stitcher.io/blog/php-81-upgrade-mac
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Upgrade to PHP 8.1 with Homebrew on Mac
Do you want to learn more about PHP 8.1? There's The Road to PHP 8.1. For the next 10 days, you'll receive a daily email covering a new and exiting feature of PHP 8.1; afterwards you'll be automatically unsubscribed, so no spam or followup. Subscribe now!
# Upgrading with Homebrew
Start by making sure brew is up-to-date:
brew update
Next, upgrade PHP. You can either use the built-in php recipe, but I recommend to use the shivammathur/homebrew-php
tap.
# Normal upgrade
brew upgrade php
# Upgrade with shivammathur/homebrew-php
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
To switch between versions, use the following command:
brew link --overwrite --force [email protected]
You can read more in the repository.
# Next steps
Check the current version by running php -v
:
php -v
Restart Nginx or Apache, if you're using Laravel Valet you can skip to the next section; you need some extra steps in order for the web server to properly work.
sudo nginx -s reload
sudo apachectl restart
And make sure that your local web server also uses PHP 8.1 by visiting this script:
# index.php, accessible to your web server
phpinfo();
The version should show 8.1.x
.
Noticed a tpyo? You can submit a PR to fix it.
If you want to stay up to date about what's happening on this blog, you can follow me on Twitter or subscribe to my newsletter:
# Valet
If you're using Laravel Valet, you should do the following steps to upgrade it:
composer global update
You can use valet use
to switch between PHP versions:
valet use [email protected]
valet use [email protected]
# Extensions
PHP extensions are installed using pecl. I personally use Redis and Xdebug. They can be installed like so:
pecl install redis
pecl install xdebug
You can run pecl list
to see which extensions are installed:
pecl list
# Installed packages, channel pecl.php.net:
# =========================================
# Package Version State
# redis 5.3.4 stable
# xdebug 3.1.1 stable
You can search for other extensions using pecl search
:
pecl search pdf
# Retrieving data...0%
# ..
# Matched packages, channel pecl.php.net:
# =======================================
# Package Stable/(Latest) Local
# pdflib 4.1.4 (stable) Creating PDF on the fly with the PDFlib library
Make sure to restart your web server after installing new packages:
sudo nginx -s reload
sudo apachectl restart
valet restart
Make sure all extensions are correctly installed and loaded by checking both your PHP webserver and CLI installs:
php -i | grep redis
var_dump(extension_loaded('redis'));
If extensions aren't properly loaded, there are two easy fixes.
First, make sure the extensions are added in the correct ini file. You can run php --ini
to know which file is loaded:
Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.1
Loaded Configuration File: /opt/homebrew/etc/php/8.1/php.ini
Scan for additional .ini files in: /opt/homebrew/etc/php/8.1/conf.d
Additional .ini files parsed: /opt/homebrew/etc/php/8.1/conf.d/error_log.ini,
/opt/homebrew/etc/php/8.1/conf.d/ext-opcache.ini,
/opt/homebrew/etc/php/8.1/conf.d/php-memory-limits.ini
Now check the ini file:
extension="redis.so"
zend_extension="xdebug.so"
Note that if you're testing installed extensions via the CLI, you don't need to restart nginx, apache or Valet when making changes to ini settings.
The second thing you can do, if you're updating from an older PHP version which also used pecl to install extension; is to reinstall every extension individually.
pecl uninstall redis
pecl install redis
# Last step
Finally you should test and upgrade your projects for PHP 8 compatibility.
Footnotes
New in PHP 8.1 — A comprehensive list of all things new in PHP 8.1
Readonly properties in PHP 8.1
Recommend
-
24
« back — written by Brent on November 26, 2020 Upgrade to PHP 8 with Homebrew on Mac ...
-
12
« back — written by Brent on November 28, 2019 Upgrade to PHP 7.4 with Homebrew on Mac ...
-
22
« back — written by Brent on March 21, 2019 Upgrade to PHP 7.3 with Homebrew on Mac ...
-
7
« back — written by Brent on November 28, 2019 Upgrade to PHP 7.4 with Homebrew on Mac ...
-
15
« back — written by Brent on March 21, 2019 Upgrade to PHP 7.3 with Homebrew on Mac ...
-
9
在 Mac 上使用 Homebrew 升级PHP到 PHP 8.1 发布:3个月前 更新:3个月前...
-
4
Mac 下 Homebrew 搭建 PHP 开发环境 发表于 2021-07...
-
3
« back — written by Brent on November 01, 2022 U...
-
3
使用 Homebrew 升级 首先确保 brew 是最新的: brew update 接下来,升级PHP。您可以使用内置的 php 配方,但我建议使用shivammathur/homebrew-php。
-
7
How to Install/Upgrade PHP 8.3 on MacOS with Homebrew Published On22 Nov 2023
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK