Home > Backend Development > PHP8 > Upgrading to PHP 8 using Homebrew on Mac

Upgrading to PHP 8 using Homebrew on Mac

藏色散人
Release: 2023-02-17 11:44:02
Original
7867 people have browsed it

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
Copy after login

Next, upgrade PHP:

brew upgrade php
Copy after login

Check the current version by running php -v:

php -v
Copy after login

Restart Nginx or Apache:

sudo nginx -s reload
sudo apachectl restart
Copy after login
Copy after login

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();
Copy after login

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
Copy after login

Now run valet install:

valet install
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

Install After the new package, make sure to restart the web server:

sudo nginx -s reload
sudo apachectl restart
Copy after login
Copy after login

If you are using Laravel Valet, you should restart it as well.

valet restart
Copy after login

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'));
Copy after login

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
Copy after login

Now check the ini file:

extension="redis.so"
extension="imagick.so"
zend_extension="xdebug.so"
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template