Install php 8 in mac

Install php 8 in mac

Check out my blog for more articles like this: https://hbakouane.dev/blog

Updating PHP in a macOS machine can be difficult, you cannot just install Xampp, MAMP, or WAMP, run it, and then you have PHP 8 in your machine, you have to go through some steps that we will be showing in this article.

If you want to upgrade to a version between 5.3 and 7.3

If so, there is an easy solution called “PHP for OS X”, which doesn’t support any version higher than PHP 7.3.

to profit from this solution: https://php-osx.liip.ch/

Upgrading to PHP 8

First things first, we have to install PHP on our machine

// Install PHP 8
// This will install the latest PHP version
brew install php
// To install a specific version, run this command:
brew install

Now if we check the current PHP version, we will still see 7.1 or another one, which means we have to make the system consider PHP 8 as the default version, to do that we have to run this command:

brew link --force 

Restart the services:

brew services start 

we still cannot see PHP 8.0 when we run

php -v or php --version

2 commands are left to make this work:

export PATH="/usr/local/opt//bin:$PATH"
export PATH="/usr/local/opt//sbin:$PATH"

And voila, we have successfully installed PHP 8.0 on our machine

php -v
// Output:
PHP 8.0.9 (cli) (built: Aug 2 2021 22:56:15) ( NTS )
Copyright (c) The PHP GroupZend Engine v4.0.9, Copyright (c) Zend Technologieswith Zend OPcache v8.0.9, Copyright (c), by Zend Technologies

I passed 3 days trying to solve this and upgrade PHP from 7.1 to 8.0 in a 2011 MacBook, no results and suddenly I ran into this answer in StackOverflow which helped me a lot and I said why not share it with others!

I hope this helped.

Check out my blog for more articles like this: https://hbakouane.dev/blog

Read More:

Integration of Laravel + VueJs + AdminLTE made easy

Models Pruning in Laravel 8.50.0 explained

5 Javascript libraries that will help you build your stunning Portfolio

A Laravel SaaS Boilerplate to start working on your next project

General-purpose scripting language

https://www.php.net/

License: PHP-3.01

Formula JSON API: /api/formula/

Bottle JSON API: /api/bottle/

Formula code: on GitHub

Bottle (binary package) installation support provided for:

Intel monterey
big sur
catalina
64-bit linux
Apple Silicon monterey
big sur

Current versions:

Other versions:

7.4.32 General-purpose scripting language
7.3.33 General-purpose scripting language
7.2.34 General-purpose scripting language

Keg-only

Depends on:

apr 1.7.0 Apache Portable Runtime library
apr-util 1.6.1 Companion library to apr, the Apache Portable Runtime library
argon2 20190702 Password hashing library and CLI utility
aspell 0.60.8 Spell checker with better logic than ispell
autoconf 2.71 Automatic configure script builder
curl 7.85.0 Get a file from an HTTP, HTTPS or FTP server
freetds 1.3.13 Libraries to talk to Microsoft SQL Server and Sybase databases
gd 2.3.3 Graphics library to dynamically manipulate images
gettext 0.21 GNU internationalization (i18n) and localization (l10n) library
gmp 6.2.1 GNU multiple precision arithmetic library
icu4c 71.1 C/C++ and Java libraries for Unicode and globalization
krb5 1.20 Network authentication protocol
libpq 14.5 Postgres C API library
libsodium 1.0.18 NaCl networking and cryptography library
libzip 1.9.2 C library for reading, creating, and modifying zip archives
oniguruma 6.9.8 Regular expressions library
openldap 2.6.3 Open source suite of directory software
1.1.1q Cryptography and SSL/TLS Toolkit
pcre2 10.40 Perl compatible regular expressions library with a new API
sqlite 3.39.4 Command-line interface for SQLite
tidy-html5 5.8.0 Granddaddy of HTML tools, with support for modern standards
unixodbc 2.3.11 ODBC 3 connectivity for UNIX

Depends on when building from source:

httpd 2.4.54 Apache HTTP server
pkg-config 0.29.2 Manage compile and link flags for libraries

To enable PHP in Apache add the following to httpd.conf and restart Apache:
     LoadModule php_module $(brew --prefix)/opt//lib/httpd/modules/libphp.so

    
     SetHandler application/x-httpd-php
    

Finally, check DirectoryIndex includes index.php
     DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
     $(brew --prefix)/etc/php/8.0/

Analytics (macOS):

Installs (30 days)
19,054
Installs on Request (30 days)
18,778
Build Errors (30 days)
3
Installs (90 days)
51,295
Installs on Request (90 days)
50,583
Installs (365 days)
172,169
Installs on Request (365 days)
166,277

Analytics (Linux):

Installs (30 days)
115
Installs on Request (30 days)
110
Build Errors (30 days)
0
Installs (90 days)
351
Installs on Request (90 days)
336
Installs (365 days)
1,252
Installs on Request (365 days)
1,140

How do I upgrade PHP to 8.0 on Mac?

Upgrading with Homebrew.
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]. ... .
Next steps. Check the current version by running php -v : php -v..

How do I get PHP on my Mac?

Install PHP on macOS Monterey.
brew --version. Installing PHP. ... .
brew install php. This will take a while and will produce some output in the Terminal window. ... .
command -v php. The command should display something like..
/usr/local/bin/php. or..
/opt/homebrew/bin/php. ... .
#!/usr/bin/env php. ... .
b) You can include inline scripts in expansions..

Is PHP already installed on Mac?

PHP is bundled with macOS since macOS X (10.0. 0) prior to macOS Monterey (12.0. 0). Compiling is similar to the Unix installation guide.

How do I upgrade PHP on Mac?

To install PHP, we can use the command brew install php . After installing a fresh PHP, set PHP to PATH using the following command. To update the PHP version, update the brew using the command brew update . Then, use the command brew upgrade php .