This article is translated from: https://stitcher.io/blog/php-8-upgrade-mac
Upgrade with Homebrew
First make sure Brew is up to date:
brew update
Next, upgrade PHP:
brew upgrade php
Check the current version by running php -v:
php -v
Restart Nginx or Apache:
sudo nginx -s reload sudo apachectl restart
and make sure your local web server is also using PHP 8 by accessing the following script:
# index.php, accessible to your web server phpinfo();
The version should show 8.0.x.
NOTE: If you are using Laravel Valet, please read on, you will need some extra steps to get your web server working properly.
Valet
If you are using Laravel Valet, you should perform the following steps to upgrade it:
composer global update
Now run valet install:
valet install
Extension
PHP extensions are installed using pecl. Personally I use Imagick, Redis and Xdebug. They can be installed like this:
pecl install imagick 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 # imagick 3.4.4 stable # redis 5.1.1 stable # xdebug 2.8.0 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.2 (stable) Creating PDF on the fly with the PDFlib library
Install After the new package, make sure to restart the web server:
sudo nginx -s reload sudo apachectl restart
If you are using Laravel Valet, you should restart it as well.
valet restart
Make sure all extensions are installed and loaded correctly by checking your PHP web server and CLI installation:
php -i | grep redis var_dump(extension_loaded('redis'));
If your extensions are not loading correctly, there are two simple fixes.
First, make sure you add the extension to the correct ini file. You can run php --ini to find out which file was loaded:
Configuration File (php.ini) Path: /usr/local/etc/php/7.4 Loaded Configuration File: /usr/local/etc/php/7.4/php.ini Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d Additional .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
Now check the ini file:
extension="redis.so" extension="imagick.so" zend_extension="xdebug.so"
Note that if you are testing an installed extension via the CLI, No need to restart nginx, apache or Valet when changing ini settings.
If you are updating from an older PHP version that also uses pecl to install extensions, you can do the second thing. is to reinstall each extension individually.
pecl uninstall imagick pecl install imagick
Final Step
Finally, you should test and upgrade your project for PHP 8 compatibility.
For more PHP8 related features, please visit the PHP8 special column!
The above is the detailed content of Upgrading to PHP 8 using Homebrew on Mac. For more information, please follow other related articles on the PHP Chinese website!