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

Upgrading to PHP 8 using Homebrew on Mac

Nov 27, 2020 am 10:09 AM

This article is translated from: https://stitcher.io/blog/php-8-upgrade-mac

Upgrade with Homebrew

First make sure Brew is up to date:

1

brew update

Copy after login

Next, upgrade PHP:

1

brew upgrade php

Copy after login

Check the current version by running php -v:

1

php -v

Copy after login

Restart Nginx or Apache:

1

2

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:

1

2

# 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:

1

composer global update

Copy after login

Now run valet install:

1

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:

1

2

3

pecl install imagick

pecl install redis

pecl install xdebug

Copy after login

You can run pecl list to see which extensions are installed:

1

2

3

4

5

6

7

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:

1

2

3

4

5

6

7

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:

1

2

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.

1

valet restart

Copy after login

Make sure all extensions are installed and loaded correctly by checking your PHP web server and CLI installation:

1

2

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:

1

2

3

4

5

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:

1

2

3

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.

1

2

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)