There’s excitement in the developer community with the release of PHP 8 on November 26, 2020. The major release brings with it new features and performance improvement for applications developed with PHP technology. Likewise, developers and business owners can expect deprecation warnings and errors, so they have to make some changes in the application’s codebase to get it running on PHP 8.
Upgrade with Homebrew
Open your terminal and make sure brew is up-to-date:
brew updateNow, you can upgrade the current PHP version to the latest release. Upgrading support using the built-in PHP recipe, or you can use this tap shivammathur/homebrew-php. We recommend using the tap since you can install multiple PHP versions allowing you to switch when needed.
Upgrading normally
brew upgrade phpUpgrading with shivammathur/homebrew-php
brew tap shivammathur/php && brew install shivammathur/php/php@8.0You can switch between versions using the following command:
brew link --overwrite --force php@8.0You can learn more about the tap here.
Verify the current version:
php -vRestart Apache or Nginx:
sudo nginx -s reloadsudo apachectl restartYou can verify your local web server uses PHP 8 by adding the code below in info.php:
# info.php, accessible to your web server
phpinfo();Note: Developers with Laravel Valet should follow the steps below to ensure the web server works properly.
Valet
Developers with Laravel Valet should follow the steps below to ensure the web server works properly.
composer global updateNow, you can install valet by running:
valet installExtensions
You can install PHP extensions with pecl. We prefer using Imagick, Redis and Xdebug:
pecl install imagick
pecl install redis
pecl install xdebugYou can run pecl list to see installed extensions:
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 stableYou 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 libraryDon’t forget to restart web server after installing new packages:
sudo nginx -s reloadsudo apachectl restartFor Laravel Valet, you can restart by using the following command:
valet restartEnsure you installed the extensions correctly:
php -i | grep redisvar_dump(extension_loaded('redis'));There are two fixes for extensions that didn’t load properly.
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: /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.iniCheck the ini file:
extension="redis.so"
extension="imagick.so"
zend_extension="xdebug.so"Reminder: you don’t have to restart Nginx, Apache or Valet if you testing installed extension via the CLI especially when you make changes to the ini settings.
The second thing you can do is to reinstall extensions individually if you are updating from an older PHP version.
pecl uninstall imagick
pecl install imagickLast Note
Don’t forget to check your project(s) is compatible with PHP 8. Need help upgrading your application(s) to PHP 8? Don’t hesitate to send us a message to see how we can help.